{"action":"closed","issue":{"url":"https://api.github.com/repos/LocateTech/hyperscan-java/issues/49","repository_url":"https://api.github.com/repos/LocateTech/hyperscan-java","labels_url":"https://api.github.com/repos/LocateTech/hyperscan-java/issues/49/labels{/name}","comments_url":"https://api.github.com/repos/LocateTech/hyperscan-java/issues/49/comments","events_url":"https://api.github.com/repos/LocateTech/hyperscan-java/issues/49/events","html_url":"https://github.com/LocateTech/hyperscan-java/issues/49","id":356228834,"node_id":"MDU6SXNzdWUzNTYyMjg4MzQ=","number":49,"title":"Double free issue using Scanner::close and Database::close","user":{"login":"ajcave","id":790921,"node_id":"MDQ6VXNlcjc5MDkyMQ==","avatar_url":"https://avatars1.githubusercontent.com/u/790921?v=4","gravatar_id":"","url":"https://api.github.com/users/ajcave","html_url":"https://github.com/ajcave","followers_url":"https://api.github.com/users/ajcave/followers","following_url":"https://api.github.com/users/ajcave/following{/other_user}","gists_url":"https://api.github.com/users/ajcave/gists{/gist_id}","starred_url":"https://api.github.com/users/ajcave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajcave/subscriptions","organizations_url":"https://api.github.com/users/ajcave/orgs","repos_url":"https://api.github.com/users/ajcave/repos","events_url":"https://api.github.com/users/ajcave/events{/privacy}","received_events_url":"https://api.github.com/users/ajcave/received_events","type":"User","site_admin":false},"labels":[{"id":562517868,"node_id":"MDU6TGFiZWw1NjI1MTc4Njg=","url":"https://api.github.com/repos/LocateTech/hyperscan-java/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"closed","locked":false,"assignee":{"login":"gliwka","id":4993665,"node_id":"MDQ6VXNlcjQ5OTM2NjU=","avatar_url":"https://avatars0.githubusercontent.com/u/4993665?v=4","gravatar_id":"","url":"https://api.github.com/users/gliwka","html_url":"https://github.com/gliwka","followers_url":"https://api.github.com/users/gliwka/followers","following_url":"https://api.github.com/users/gliwka/following{/other_user}","gists_url":"https://api.github.com/users/gliwka/gists{/gist_id}","starred_url":"https://api.github.com/users/gliwka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gliwka/subscriptions","organizations_url":"https://api.github.com/users/gliwka/orgs","repos_url":"https://api.github.com/users/gliwka/repos","events_url":"https://api.github.com/users/gliwka/events{/privacy}","received_events_url":"https://api.github.com/users/gliwka/received_events","type":"User","site_admin":false},"assignees":[{"login":"gliwka","id":4993665,"node_id":"MDQ6VXNlcjQ5OTM2NjU=","avatar_url":"https://avatars0.githubusercontent.com/u/4993665?v=4","gravatar_id":"","url":"https://api.github.com/users/gliwka","html_url":"https://github.com/gliwka","followers_url":"https://api.github.com/users/gliwka/followers","following_url":"https://api.github.com/users/gliwka/following{/other_user}","gists_url":"https://api.github.com/users/gliwka/gists{/gist_id}","starred_url":"https://api.github.com/users/gliwka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gliwka/subscriptions","organizations_url":"https://api.github.com/users/gliwka/orgs","repos_url":"https://api.github.com/users/gliwka/repos","events_url":"https://api.github.com/users/gliwka/events{/privacy}","received_events_url":"https://api.github.com/users/gliwka/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2018-09-01T19:59:15Z","updated_at":"2018-09-04T21:03:07Z","closed_at":"2018-09-04T21:03:07Z","author_association":"NONE","body":"First, thanks a lot for these bindings! I was able to get a pretty significant performance improvement in my use-case quite easily by switching from the naive \"loop over all the regexes\" algorithm to using these hyperscan bindings :)\r\n\r\nIn my use-case I was creating a lot of Scanners in try-with-resources blocks one after the other. (I know it's not ideal to be re-allocating them unnecessarily, but it was the quickest way to a working prototype in my case). And sometimes I was getting an `InvalidParameterException(\"An invalid parameter has been passed. Is scratch allocated?\")` from scanning.\r\n\r\nI'm pretty sure I've tracked this down to the [implementation of `close()` and `finalize()`](https://github.com/LocateTech/hyperscan-java/blob/d0a08fdcf2e2840ef0639cd24d05b545b7131443/src/main/java/com/gliwka/hyperscan/wrapper/Scanner.java#L129)\r\n\r\nThe problem is, when `close()` is called (via try-with-resources or otherwise) the scratch space is freed, and then at some later point `finalize()` might run and trigger a double free. My working theory is that in my case, it sometimes happened that between closing the first Scanner and executing the finalizer a new Scanner was allocated at the same address, and the second free in the finalizer deallocated the new one I was just about to use!\r\n"}}
{"actor":{"display_login":"gliwka"}}