{"action":"created","issue":{"url":"https://api.github.com/repos/openssl/openssl/issues/2115","repository_url":"https://api.github.com/repos/openssl/openssl","labels_url":"https://api.github.com/repos/openssl/openssl/issues/2115/labels{/name}","comments_url":"https://api.github.com/repos/openssl/openssl/issues/2115/comments","events_url":"https://api.github.com/repos/openssl/openssl/issues/2115/events","html_url":"https://github.com/openssl/openssl/issues/2115","id":196363250,"number":2115,"title":"memory leak in CRYPTO_set_ex_data","user":{"login":"bernd-edlinger","id":17638929,"avatar_url":"https://avatars.githubusercontent.com/u/17638929?v=3","gravatar_id":"","url":"https://api.github.com/users/bernd-edlinger","html_url":"https://github.com/bernd-edlinger","followers_url":"https://api.github.com/users/bernd-edlinger/followers","following_url":"https://api.github.com/users/bernd-edlinger/following{/other_user}","gists_url":"https://api.github.com/users/bernd-edlinger/gists{/gist_id}","starred_url":"https://api.github.com/users/bernd-edlinger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bernd-edlinger/subscriptions","organizations_url":"https://api.github.com/users/bernd-edlinger/orgs","repos_url":"https://api.github.com/users/bernd-edlinger/repos","events_url":"https://api.github.com/users/bernd-edlinger/events{/privacy}","received_events_url":"https://api.github.com/users/bernd-edlinger/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-19T09:09:23Z","updated_at":"2016-12-19T18:33:29Z","closed_at":null,"body":"Under low memory a memory leak was observed with openssl-1.0.2j:\r\n\r\nReason is a bit unclear, probably it is possible that in def_get_class\r\nan unnoticed error happens on lh_EX_CLASS_ITEM_insert, which\r\nmakes int_new_ex_data succeed, but int_free_ex_data fails,\r\nand does not even remove the sk object.\r\n\r\nThe following patch makes the memory leak go away.\r\nThe first hunk may be unnecessary.\r\n\r\n```\r\nDirect leak of 32 byte(s) in 1 object(s) allocated from:\r\n    #0 0x7f6ba50fa310 in __interceptor_malloc ../../../../gcc-7-20161211/libsanitizer/asan/asan_malloc_linux.cc:62\r\n    #1 0x2153e5a in CRYPTO_malloc crypto/mem.c:346\r\n    #2 0x21ac96c in sk_new crypto/stack/stack.c:162\r\n    #3 0x21ac96c in sk_new_null crypto/stack/stack.c:154\r\n    #4 0x215920c in CRYPTO_set_ex_data crypto/ex_data.c:614\r\n    #5 0x236b017 in ssl_verify_cert_chain ssl/ssl_cert.c:734\r\n    #6 0x239dd44 in ssl3_get_server_certificate ssl/s3_clnt.c:1255\r\n    #7 0x23aacc8 in ssl3_connect ssl/s3_clnt.c:345\r\n    #8 0x233e3ae in ssl23_get_server_hello ssl/s23_clnt.c:799\r\n    #9 0x233e3ae in ssl23_connect ssl/s23_clnt.c:228\r\n    #10 0x233f744 in ssl23_write ssl/s23_lib.c:173\r\n\r\n--- crypto/ex_data.c.orig       2016-09-26 11:49:07.000000000 +0200\r\n+++ crypto/ex_data.c    2016-12-17 19:02:12.862512254 +0100\r\n@@ -501,9 +501,9 @@ static void int_free_ex_data(int class_i\r\n     void *ptr;\r\n     CRYPTO_EX_DATA_FUNCS **storage = NULL;\r\n     if (ex_data == NULL)\r\n-        return;\r\n+        goto err;\r\n     if ((item = def_get_class(class_index)) == NULL)\r\n-        return;\r\n+        goto err;\r\n     CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);\r\n     mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);\r\n     if (mx > 0) {\r\n@@ -517,7 +517,7 @@ static void int_free_ex_data(int class_i\r\n     CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);\r\n     if ((mx > 0) && !storage) {\r\n         CRYPTOerr(CRYPTO_F_INT_FREE_EX_DATA, ERR_R_MALLOC_FAILURE);\r\n-        return;\r\n+        goto err;\r\n     }\r\n     for (i = 0; i < mx; i++) {\r\n         if (storage[i] && storage[i]->free_func) {\r\n@@ -528,6 +528,7 @@ static void int_free_ex_data(int class_i\r\n     }\r\n     if (storage)\r\n         OPENSSL_free(storage);\r\n+ err:\r\n     if (ad->sk) {\r\n         sk_void_free(ad->sk);\r\n         ad->sk = NULL;\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/openssl/openssl/issues/comments/268041184","html_url":"https://github.com/openssl/openssl/issues/2115#issuecomment-268041184","issue_url":"https://api.github.com/repos/openssl/openssl/issues/2115","id":268041184,"user":{"login":"richsalz","id":7332500,"avatar_url":"https://avatars.githubusercontent.com/u/7332500?v=3","gravatar_id":"","url":"https://api.github.com/users/richsalz","html_url":"https://github.com/richsalz","followers_url":"https://api.github.com/users/richsalz/followers","following_url":"https://api.github.com/users/richsalz/following{/other_user}","gists_url":"https://api.github.com/users/richsalz/gists{/gist_id}","starred_url":"https://api.github.com/users/richsalz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richsalz/subscriptions","organizations_url":"https://api.github.com/users/richsalz/orgs","repos_url":"https://api.github.com/users/richsalz/repos","events_url":"https://api.github.com/users/richsalz/events{/privacy}","received_events_url":"https://api.github.com/users/richsalz/received_events","type":"User","site_admin":false},"created_at":"2016-12-19T18:33:29Z","updated_at":"2016-12-19T18:33:29Z","body":"@bernd-edlinger  at this point you've opened more than 20 issues/bugfixes.  We have gotten past the point of considering these to be trivial  Please sign our CLA."}}
{"actor":{"display_login":"richsalz"}}