{"action":"opened","issue":{"url":"https://api.github.com/repos/antirez/disque/issues/81","labels_url":"https://api.github.com/repos/antirez/disque/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/antirez/disque/issues/81/comments","events_url":"https://api.github.com/repos/antirez/disque/issues/81/events","html_url":"https://github.com/antirez/disque/issues/81","id":87098362,"number":81,"title":"Code errors discovered by static analysis","user":{"login":"bos","id":23374,"avatar_url":"https://avatars.githubusercontent.com/u/23374?v=3","gravatar_id":"","url":"https://api.github.com/users/bos","html_url":"https://github.com/bos","followers_url":"https://api.github.com/users/bos/followers","following_url":"https://api.github.com/users/bos/following{/other_user}","gists_url":"https://api.github.com/users/bos/gists{/gist_id}","starred_url":"https://api.github.com/users/bos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bos/subscriptions","organizations_url":"https://api.github.com/users/bos/orgs","repos_url":"https://api.github.com/users/bos/repos","events_url":"https://api.github.com/users/bos/events{/privacy}","received_events_url":"https://api.github.com/users/bos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-10T20:35:06Z","updated_at":"2015-06-10T20:35:06Z","closed_at":null,"body":"I've run a static analyzer over `master` (b5264359ddf0aa04a49b921c383c49ded7e7eea6 at the time of writing), and found some problems with memory management. They all involve failure to check the results of memory allocations, so in a low-memory situation, disque is simply going to crash.\r\n\r\n`redisAsyncInitialize` may return `NULL`, but its result is not checked.\r\n\r\n```\r\ndisque/deps/hiredis/async.c:172: error: NULL_DEREFERENCE\r\n  [B1] pointer ac last assigned on line 171 could be null and is dereferenced by call to __redisAsyncCopyError() at line 172, column 5\r\n```\r\n\r\nFailures to check result of `malloc`. Perhaps something like an `xmalloc` wrapper would be appropriate.\r\n\r\n```\r\ndisque/deps/hiredis/dict.c:75: error: NULL_DEREFERENCE\r\n  [B1] pointer ht last assigned on line 74 could be null and is dereferenced by call to _dictInit() at line 75, column 5\r\n\r\ndisque/deps/hiredis/dict.c:261: error: NULL_DEREFERENCE\r\n  [B1] pointer iter last assigned on line 259 could be null and is dereferenced at line 261, column 5\r\n```\r\n\r\n`redisContextInit` may return `NULL`, but its result is not checked.\r\n\r\n```\r\ndisque/deps/hiredis/hiredis.c:1062: error: NULL_DEREFERENCE\r\n  [B1] pointer c last assigned on line 1061 could be null and is dereferenced at line 1062, column 5\r\n```\r\n\r\nIt looks like `zrealloc` is simply `realloc`, and its result is not checked for `NULL`.\r\n\r\n```\r\ndeps/hiredis/sds.c:160: error: NULL_DEREFERENCE\r\n  [B1] pointer sh last assigned on line 159 could be null and is dereferenced at line 160, column 5\r\n```\r\n"}}