From: Arjun Sreedharan <arjun024@gmail•com>
To: git mailing list <git@vger•kernel.org>,
Junio C Hamano <gitster@pobox•com>
Subject: [PATCH] win32: syslog: prevent potential realloc memory leak
Date: Sat, 13 Dec 2014 15:11:16 +0530 [thread overview]
Message-ID: <1418463676-1753-1-git-send-email-arjun024@gmail.com> (raw)
use a temporary variable to free the memory in case
realloc() fails.
Signed-off-by: Arjun Sreedharan <arjun024@gmail•com>
---
compat/win32/syslog.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c
index d015e43..3409e43 100644
--- a/compat/win32/syslog.c
+++ b/compat/win32/syslog.c
@@ -16,7 +16,7 @@ void openlog(const char *ident, int logopt, int facility)
void syslog(int priority, const char *fmt, ...)
{
WORD logtype;
- char *str, *pos;
+ char *str, *str_temp, *pos;
int str_len;
va_list ap;
@@ -43,9 +43,11 @@ void syslog(int priority, const char *fmt, ...)
va_end(ap);
while ((pos = strstr(str, "%1")) != NULL) {
+ str_temp = str;
str = realloc(str, ++str_len + 1);
if (!str) {
warning("realloc failed: '%s'", strerror(errno));
+ free(str_temp);
return;
}
memmove(pos + 2, pos + 1, strlen(pos));
--
1.8.1.msysgit.1
next reply other threads:[~2014-12-13 9:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-13 9:41 Arjun Sreedharan [this message]
2014-12-15 18:11 ` [PATCH] win32: syslog: prevent potential realloc memory leak Junio C Hamano
2015-01-25 21:38 ` Erik Faye-Lund
2015-01-26 4:25 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1418463676-1753-1-git-send-email-arjun024@gmail.com \
--to=arjun024@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox