use a temporary variable to free the memory in case
realloc() fails.

Signed-off-by: Arjun Sreedharan <[email protected]>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to