git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] win32: plug memory leak on realloc() failure in syslog()

From
René Scharfe <l.s.r@web.de>
Date
Aug 10, 2017, 10:23 UTC
Message-ID
<245410ce-1f4c-f2a9-fd8d-98ff2d2c0335@web.de>

If realloc() fails then the original buffer is still valid. Free it before exiting the function.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 compat/win32/syslog.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c
index 6c7c9b6053..161978d720 100644
--- a/compat/win32/syslog.c
+++ b/compat/win32/syslog.c
@@ -43,8 +43,10 @@ void syslog(int priority, const char *fmt, ...)
 	va_end(ap);
 
 	while ((pos = strstr(str, "%1")) != NULL) {
+		char *oldstr = str;
 		str = realloc(str, st_add(++str_len, 1));
 		if (!str) {
+			free(oldstr);
 			warning_errno("realloc failed");
 			return;
 		}
-- 
2.14.0
Next: Johannes Schindelin
Message 1 of 2 in “win32: plug memory leak on realloc() failure in syslog()”
  1. win32: plug memory leak on realloc() failure in syslog()René Scharfe, Aug 10, 2017
  2. Johannes SchindelinAug 14, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.