{"action":"created","issue":{"url":"https://api.github.com/repos/robotology/yarp/issues/482","labels_url":"https://api.github.com/repos/robotology/yarp/issues/482/labels{/name}","comments_url":"https://api.github.com/repos/robotology/yarp/issues/482/comments","events_url":"https://api.github.com/repos/robotology/yarp/issues/482/events","html_url":"https://github.com/robotology/yarp/pull/482","id":70079487,"number":482,"title":"Fix: RF module calls close if configure fails","user":{"login":"barbalberto","id":4061020,"avatar_url":"https://avatars.githubusercontent.com/u/4061020?v=3","gravatar_id":"","url":"https://api.github.com/users/barbalberto","html_url":"https://github.com/barbalberto","followers_url":"https://api.github.com/users/barbalberto/followers","following_url":"https://api.github.com/users/barbalberto/following{/other_user}","gists_url":"https://api.github.com/users/barbalberto/gists{/gist_id}","starred_url":"https://api.github.com/users/barbalberto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barbalberto/subscriptions","organizations_url":"https://api.github.com/users/barbalberto/orgs","repos_url":"https://api.github.com/users/barbalberto/repos","events_url":"https://api.github.com/users/barbalberto/events{/privacy}","received_events_url":"https://api.github.com/users/barbalberto/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-04-22T09:57:20Z","updated_at":"2015-04-23T14:50:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/robotology/yarp/pulls/482","html_url":"https://github.com/robotology/yarp/pull/482","diff_url":"https://github.com/robotology/yarp/pull/482.diff","patch_url":"https://github.com/robotology/yarp/pull/482.patch"},"body":"I found that robotInterface was crashing if the configure function fails. It turns out that I had to explixitly call the close function in order to clean up things.\r\n So me and @drdanz thought that maybe it'll be easier for user if the RFModule will call the close function by his own if the configure fails, like in the patch proposed.\r\n\r\n@paulfitz @lornat75 what di you think about it? Do you see any drawback?\r\n\r\nMaybe also the stopModule could call the close?"},"comment":{"url":"https://api.github.com/repos/robotology/yarp/issues/comments/95611242","html_url":"https://github.com/robotology/yarp/pull/482#issuecomment-95611242","issue_url":"https://api.github.com/repos/robotology/yarp/issues/482","id":95611242,"user":{"login":"pattacini","id":3738070,"avatar_url":"https://avatars.githubusercontent.com/u/3738070?v=3","gravatar_id":"","url":"https://api.github.com/users/pattacini","html_url":"https://github.com/pattacini","followers_url":"https://api.github.com/users/pattacini/followers","following_url":"https://api.github.com/users/pattacini/following{/other_user}","gists_url":"https://api.github.com/users/pattacini/gists{/gist_id}","starred_url":"https://api.github.com/users/pattacini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pattacini/subscriptions","organizations_url":"https://api.github.com/users/pattacini/orgs","repos_url":"https://api.github.com/users/pattacini/repos","events_url":"https://api.github.com/users/pattacini/events{/privacy}","received_events_url":"https://api.github.com/users/pattacini/received_events","type":"User","site_admin":false},"created_at":"2015-04-23T14:50:27Z","updated_at":"2015-04-23T14:50:27Z","body":"@drdanz my main concern is related to situations as the one sketched below, which are likely spread around in the user code:\r\n\r\n```cpp\r\nbool configure() {\r\n    Class *class=new Class();\r\n    if (!isOk) {\r\n        delete class;\r\n        return false;\r\n    }\r\n}\r\n\r\nbool close() {\r\n    delete class;\r\n    return true;\r\n}\r\n```\r\n\r\nWith the proposed change we'll have a seg-fault if `isOk==false` (it's a good rule to put `class=NULL;` after deletion, but who knows).\r\n\r\nOther times, the use might rely on a `terminate()` helper which in turn gets called both in `configure()` and `close()` for object disposal, as for example done in [depth2kin](https://github.com/robotology/icub-main/blob/master/src/tools/depth2kin/src/module.cpp#L967).\r\n\r\nThe handling through the `closeOnConfigureFailure` option seems a quite nice solution."}}