Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions PC/bdist_wininst/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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)) {
Expand All @@ -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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The memory pointed by the old value of lines is leaked if realloc() returns NULL.

And seems lines is leaked in the code below.

fclose(logfile);
return SystemError(0, "Out of memory");
}
}
}
fclose(logfile);
Expand Down