git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] win32: plug memory leak on realloc() failure in syslog()
@ 2017-08-10 10:23 René Scharfe
  2017-08-14 20:26 ` Johannes Schindelin
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2017-08-10 10:23 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Johannes Schindelin

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] win32: plug memory leak on realloc() failure in syslog()
  2017-08-10 10:23 [PATCH] win32: plug memory leak on realloc() failure in syslog() René Scharfe
@ 2017-08-14 20:26 ` Johannes Schindelin
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Schindelin @ 2017-08-14 20:26 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 405 bytes --]

Hi René,

On Thu, 10 Aug 2017, René Scharfe wrote:

> 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>

The subject had me worried for a second... The realloc() fails so rarely
that I, for one, have never encountered that problem.

Still, it is a correct fix for a real bug.

Thanks,
Dscho

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-14 20:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-10 10:23 [PATCH] win32: plug memory leak on realloc() failure in syslog() René Scharfe
2017-08-14 20:26 ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).