Skip to content

Commit

Permalink
upnpsoap: Prevent memory leaks upon return.
Browse files Browse the repository at this point in the history
When we return with a failure of malloc, we may need to free the memory that
may have been allocated before or we will have a memory leak.

We also initialize the pointers in question to NULL to avoid calling free
with potential garbage.
  • Loading branch information
Rogério Brito committed Sep 13, 2011
1 parent e086475 commit afaa5b1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/inotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ int
inotify_insert_file(char * name, const char * path)
{
int len;
char * last_dir;
char * path_buf;
char * base_name;
char * last_dir = NULL;
char * path_buf = NULL;
char * base_name = NULL;
char * base_copy;
char * parent_buf = NULL;
char * id = NULL;
Expand Down Expand Up @@ -356,8 +356,13 @@ inotify_insert_file(char * name, const char * path)
len = strlen(path)+1;
if( !(path_buf = malloc(len)) ||
!(last_dir = malloc(len)) ||
!(base_name = malloc(len)) )
!(base_name = malloc(len)) ) {
free(path_buf);
free(last_dir);
free(base_name);
return -1;
}

base_copy = base_name;
while( depth )
{
Expand Down

0 comments on commit afaa5b1

Please sign in to comment.