From ec3e3fa6ad3f4cc9a988ad10799e6675b217830a Mon Sep 17 00:00:00 2001 From: Tiago Filipe Silva Date: Tue, 13 Jun 2017 00:52:30 +0100 Subject: [PATCH] Fixed a few leaks This commit fixes a few memory leaks in /PC/bdist_wininst/install.c --- PC/bdist_wininst/install.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/PC/bdist_wininst/install.c b/PC/bdist_wininst/install.c index 4f9ef6c2cc4c77..a17fa5fe48e520 100644 --- a/PC/bdist_wininst/install.c +++ b/PC/bdist_wininst/install.c @@ -2371,13 +2371,17 @@ void DeleteRegistryKey(char *string) line = strdup(string); /* so we can change it */ keyname = strchr(line, '['); - if (!keyname) + if (!keyname) { + free(line); return; + } ++keyname; subkeyname = strchr(keyname, ']'); - if (!subkeyname) + if (!subkeyname) { + free(line); return; + } *subkeyname++='\0'; delim = strchr(subkeyname, '\n'); if (delim) @@ -2413,16 +2417,22 @@ void DeleteRegistryValue(char *string) /* Format is 'Reg DB Value: [key]name=value' */ keyname = strchr(line, '['); - if (!keyname) + if (!keyname) { + free(line); return; + } ++keyname; valuename = strchr(keyname, ']'); - if (!valuename) + if (!valuename) { + free(line); return; + } *valuename++ = '\0'; value = strchr(valuename, '='); - if (!value) + if (!value) { + free(line); return; + } *value++ = '\0'; @@ -2538,8 +2548,10 @@ int DoUninstall(int argc, char **argv) } lines = (char **)malloc(sizeof(char *) * lines_buffer_size); - if (!lines) + if (!lines) { + fclose(logfile); return SystemError(0, "Out of memory"); + } /* Read the whole logfile, realloacting the buffer */ while (fgets(buffer, sizeof(buffer), logfile)) { @@ -2553,8 +2565,10 @@ int DoUninstall(int argc, char **argv) lines_buffer_size += 10; lines = (char **)realloc(lines, sizeof(char *) * lines_buffer_size); - if (!lines) + if (!lines) { + fclose(logfile); return SystemError(0, "Out of memory"); + } } } fclose(logfile);