Browse Source

libdpkg: Do not leak every tar_entry name and linkname members

The only free()ed members were the last ones.
Guillem Jover 12 years ago
parent
commit
6f5374204b
3 changed files with 4 additions and 2 deletions
  1. 0 1
      TODO
  2. 1 0
      debian/changelog
  3. 3 1
      lib/dpkg/tarfn.c

+ 0 - 1
TODO

@@ -52,7 +52,6 @@ TODO
    - Handle instdir '/' separator consistently.
    - Check if caching selinux context for second call is possible.
    - Add missing newlines in --version output.
-   - Fix leak on tar_extract (name, linkname).
    - Handle symlinks in statcmd.c statdb_node_apply().
    - Fix dpkg termination on SIGPIPE from status-fd.
 

+ 1 - 0
debian/changelog

@@ -26,6 +26,7 @@ dpkg (1.16.2) UNRELEASED; urgency=low
     using the ‘--warning=no-timestamp’ option. Closes: 642802
   * Do not segfault on GNU/Linux when dpkg cannot retrieve the block size
     for the filesystem containing the info database. LP: #872734
+  * Fix two memory leaks per tar entry in the tar extractor used on unpack.
 
   [ Raphaël Hertzog ]
   * Update Dpkg::Shlibs to look into multiarch paths when cross-building

+ 3 - 1
lib/dpkg/tarfn.c

@@ -308,6 +308,7 @@ tar_extractor(void *ctx, const struct tar_operations *ops)
 				errno = 0;
 				status = -1;
 			}
+			tar_entry_destroy(&h);
 			break;
 		}
 		if (h.type != tar_filetype_gnu_longlink &&
@@ -326,6 +327,7 @@ tar_extractor(void *ctx, const struct tar_operations *ops)
 			/* Indicates broken tarfile: “Bad header data”. */
 			errno = 0;
 			status = -1;
+			tar_entry_destroy(&h);
 			break;
 		}
 
@@ -378,6 +380,7 @@ tar_extractor(void *ctx, const struct tar_operations *ops)
 			errno = 0;
 			status = -1;
 		}
+		tar_entry_destroy(&h);
 		if (status != 0)
 			/* Pass on status from coroutine. */
 			break;
@@ -391,7 +394,6 @@ tar_extractor(void *ctx, const struct tar_operations *ops)
 		free(symlink_head);
 		symlink_head = symlink_node;
 	}
-	tar_entry_destroy(&h);
 
 	if (status > 0) {
 		/* Indicates broken tarfile: “Read partial header record”. */