{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/hhvm/issues/6215","labels_url":"https://api.github.com/repos/facebook/hhvm/issues/6215/labels{/name}","comments_url":"https://api.github.com/repos/facebook/hhvm/issues/6215/comments","events_url":"https://api.github.com/repos/facebook/hhvm/issues/6215/events","html_url":"https://github.com/facebook/hhvm/issues/6215","id":105715118,"number":6215,"title":"Destroying uninitialized data with an HNI constructor for a NativeData","user":{"login":"Orvid","id":709247,"avatar_url":"https://avatars.githubusercontent.com/u/709247?v=3","gravatar_id":"","url":"https://api.github.com/users/Orvid","html_url":"https://github.com/Orvid","followers_url":"https://api.github.com/users/Orvid/followers","following_url":"https://api.github.com/users/Orvid/following{/other_user}","gists_url":"https://api.github.com/users/Orvid/gists{/gist_id}","starred_url":"https://api.github.com/users/Orvid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Orvid/subscriptions","organizations_url":"https://api.github.com/users/Orvid/orgs","repos_url":"https://api.github.com/users/Orvid/repos","events_url":"https://api.github.com/users/Orvid/events{/privacy}","received_events_url":"https://api.github.com/users/Orvid/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-10T01:32:17Z","updated_at":"2015-09-14T21:08:20Z","closed_at":"2015-09-14T21:08:20Z","body":"Attempting to call an HNI constructor for a NativeData object, with invalid parameter types, results in attempting to destroy the NativeData object before it's been initialized.\r\n\r\nIf we take the following Native Data structure:\r\n```C++\r\nstruct ZMQCert {\r\n  zcert_t* zcert;\r\n  ~ZMQCert() {\r\n    if (zcert) {\r\n      zcert_destroy(&zcert);\r\n    }\r\n  }\r\n};\r\n```\r\nAnd we have its constructor defined an registered as:\r\n```C++\r\nvoid HHVM_METHOD(ZMQCert, __construct, const Variant& filename) {\r\n  auto cert = Native::data<ZMQCert>(this_);\r\n\r\n  if (filename.isNull()) {\r\n    cert->zcert = zcert_new();\r\n  } else {\r\n    cert->zcert = zcert_load(filename.asCStrRef().c_str());\r\n  }\r\n}\r\n```\r\nAnd declared in the system library as:\r\n```PHP\r\n<<__NativeData(\"ZMQCert\")>>\r\nclass ZMQCert {\r\n  <<__Native>>\r\n  public final function __construct(?string $filename = null): void;\r\n}\r\n```\r\n\r\nAttempting to call it like this:\r\n```PHP\r\ndate_default_timezone_set('Europe/London');\r\n$dateTime = new DateTime();\r\n\r\ntry {\r\n  $cert = new ZMQCert($dateTime);\r\n} catch (ZMQCertException $e) {\r\n  var_dump($e->getMessage());\r\n}\r\n```\r\n\r\nResults in a call to `ZMQCert::~ZMQCert()` with an instance that hasn't been initialized yet, which in turn ends up causing a segfault inside of `zcert_destroy`."},"comment":{"url":"https://api.github.com/repos/facebook/hhvm/issues/comments/140206422","html_url":"https://github.com/facebook/hhvm/issues/6215#issuecomment-140206422","issue_url":"https://api.github.com/repos/facebook/hhvm/issues/6215","id":140206422,"user":{"login":"Orvid","id":709247,"avatar_url":"https://avatars.githubusercontent.com/u/709247?v=3","gravatar_id":"","url":"https://api.github.com/users/Orvid","html_url":"https://github.com/Orvid","followers_url":"https://api.github.com/users/Orvid/followers","following_url":"https://api.github.com/users/Orvid/following{/other_user}","gists_url":"https://api.github.com/users/Orvid/gists{/gist_id}","starred_url":"https://api.github.com/users/Orvid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Orvid/subscriptions","organizations_url":"https://api.github.com/users/Orvid/orgs","repos_url":"https://api.github.com/users/Orvid/repos","events_url":"https://api.github.com/users/Orvid/events{/privacy}","received_events_url":"https://api.github.com/users/Orvid/received_events","type":"User","site_admin":false},"created_at":"2015-09-14T21:08:20Z","updated_at":"2015-09-14T21:08:20Z","body":"So, the answer is that I am simply too used to default-initialized languages -_-... Huzzah?"}}