{"thread":{"id":"46555","subject":"[PATCH] win32: plug memory leak on realloc() failure in syslog()","startedAt":"2017-08-10T10:24:12Z","lastAt":"2017-08-14T20:26:56Z","messageCount":2,"participants":["René Scharfe","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"326025","messageId":"245410ce-1f4c-f2a9-fd8d-98ff2d2c0335@web.de","threadId":"46555","inReplyTo":null,"subject":"[PATCH] win32: plug memory leak on realloc() failure in syslog()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-08-10T10:23:45Z","receivedAt":"2017-08-10T10:24:12Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"If realloc() fails then the original buffer is still valid.  Free it\nbefore exiting the function.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n compat/win32/syslog.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/compat/win32/syslog.c b/compat/win32/syslog.c\nindex 6c7c9b6053..161978d720 100644\n--- a/compat/win32/syslog.c\n+++ b/compat/win32/syslog.c\n@@ -43,8 +43,10 @@ void syslog(int priority, const char *fmt, ...)\n \tva_end(ap);\n \n \twhile ((pos = strstr(str, \"%1\")) != NULL) {\n+\t\tchar *oldstr = str;\n \t\tstr = realloc(str, st_add(++str_len, 1));\n \t\tif (!str) {\n+\t\t\tfree(oldstr);\n \t\t\twarning_errno(\"realloc failed\");\n \t\t\treturn;\n \t\t}\n-- \n2.14.0\n"},{"id":"326306","messageId":"alpine.DEB.2.21.1.1708142225330.19382@virtualbox","threadId":"46555","inReplyTo":"245410ce-1f4c-f2a9-fd8d-98ff2d2c0335@web.de","subject":"Re: [PATCH] win32: plug memory leak on realloc() failure in syslog()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2017-08-14T20:26:45Z","receivedAt":"2017-08-14T20:26:56Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi René,\n\nOn Thu, 10 Aug 2017, René Scharfe wrote:\n\n> If realloc() fails then the original buffer is still valid.  Free it\n> before exiting the function.\n> \n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n\nThe subject had me worried for a second... The realloc() fails so rarely\nthat I, for one, have never encountered that problem.\n\nStill, it is a correct fix for a real bug.\n\nThanks,\nDscho"}]}