Browse Source

Fix memory leak in magic loader. Closes: #840754

Christoph Biedl 8 years ago
parent
commit
c669a34f3a

+ 32 - 0
debian/patches/cherry-pick.FILE5_24-31-g3aa35aa.dont-leak-memory-when-loading-non-compiled-files.patch

@@ -0,0 +1,32 @@
+Subject: Don't leak memory when loading non-compiled files
+Origin: FILE5_24-31-g3aa35aa
+Upstream-Author: Christos Zoulas <christos@zoulas.com>
+Date: Thu Sep 10 13:59:47 2015 +0000
+
+--- a/src/apprentice.c
++++ b/src/apprentice.c
+@@ -538,6 +538,7 @@
+ private void
+ apprentice_unmap(struct magic_map *map)
+ {
++	size_t i;
+ 	if (map == NULL)
+ 		return;
+ 
+@@ -550,6 +551,8 @@
+ #endif
+ 	case MAP_TYPE_MALLOC:
+ 		free(map->p);
++		for (i = 0; i < MAGIC_SETS; i++)
++			free(map->magic[i]);
+ 		break;
+ 	case MAP_TYPE_USER:
+ 		break;
+@@ -1285,6 +1288,7 @@
+ 		file_oomem(ms, sizeof(*map));
+ 		return NULL;
+ 	}
++	map->type = MAP_TYPE_MALLOC;
+ 
+ 	/* print silly verbose header for USG compat. */
+ 	if (action == FILE_CHECK)

+ 22 - 0
debian/patches/cherry-pick.FILE5_28-42-g10ee4ec.pr-569-shi-yin-fix-memory-leak.patch

@@ -0,0 +1,22 @@
+Subject: PR/569: Shi Yin: Fix memory leak
+Origin: FILE5_28-42-g10ee4ec
+Upstream-Author: Christos Zoulas <christos@zoulas.com>
+Date: Sun Sep 11 13:53:02 2016 +0000
+Comment: Only relevant parts of that commit were used
+
+--- a/src/apprentice.c
++++ b/src/apprentice.c
+@@ -404,11 +404,11 @@
+ {
+ 	struct mlist *ml;
+ 
+-	mlp->map = idx == 0 ? map : NULL;
++	mlp->map = NULL;
+ 	if ((ml = CAST(struct mlist *, malloc(sizeof(*ml)))) == NULL)
+ 		return -1;
+ 
+-	ml->map = NULL;
++	ml->map = idx == 0 ? map : NULL;
+ 	ml->magic = map->magic[idx];
+ 	ml->nmagic = map->nmagic[idx];
+ 

+ 2 - 0
debian/patches/series

@@ -13,3 +13,5 @@
 cherry-pick.FILE5_24-22-g27b4e34.parameter-1.patch
 cherry-pick.FILE5_24-23-g4ddb783.parameter-2.patch
 CVE-2015-8865.6713ca4.patch
+cherry-pick.FILE5_24-31-g3aa35aa.dont-leak-memory-when-loading-non-compiled-files.patch
+cherry-pick.FILE5_28-42-g10ee4ec.pr-569-shi-yin-fix-memory-leak.patch