Memory leak in modules/access/zip/zipstream.c
Working off git, revision c432a4e1 :
Note: This bug was found with Clang.
In modules/access/zip/zipstream.c
691 static node* findOrCreateParentNode( node *root, const char *fullpath )
692 {
//...
694 char *path = strdup( fullpath ); // Allocate memory
695 folder = path;
//...
699 char *sep = strchr( folder, '/' );
700 if( !sep ) // Assume sep is not null (the first time)
701 {
702 free( path );
703 return root;
704 }
705
706 *sep = '\0';
707 ++sep;
708
709 node *current = root->child;
710
711 while( current ) // Assume this is true
712 {
713 if( !strcmp( current->name, folder ) )// Taking true branch
714 {
715 /* We found the folder, go recursively deeper */
716 return findOrCreateParentNode( current, sep ); // Leak of memory pointed to by 'folder'
The problem is that the memory stored in path
is only freed in the final call to findOrCreateParentNode
, it is not freed on any of the previous calls.
One possible solution for this is relatively simple:
Replace:
715 /* We found the folder, go recursively deeper */
716 return findOrCreateParentNode( current, sep ); // Leak of memory pointed to by 'folder'
with:
715 /* We found the folder, go recursively deeper */
716 node * parentNode = findOrCreateParentNode( current, sep );
717 free( path ); // Free the memory pointed to by 'folder'
718 return parentNode; // Now it's safe to exit