Skip to content

Commit a06eed8

Browse files
WOnder93gregkh
authored andcommitted
selinux: fix memory leak in policydb_init()
commit 4538523 upstream. Since roles_init() adds some entries to the role hash table, we need to destroy also its keys/values on error, otherwise we get a memory leak in the error path. Cc: <[email protected]> Reported-by: [email protected] Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Paul Moore <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5040b84 commit a06eed8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: security/selinux/ss/policydb.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)
272272
return v;
273273
}
274274

275+
static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap);
276+
275277
/*
276278
* Initialize a policy database structure.
277279
*/
@@ -319,8 +321,10 @@ static int policydb_init(struct policydb *p)
319321
out:
320322
hashtab_destroy(p->filename_trans);
321323
hashtab_destroy(p->range_tr);
322-
for (i = 0; i < SYM_NUM; i++)
324+
for (i = 0; i < SYM_NUM; i++) {
325+
hashtab_map(p->symtab[i].table, destroy_f[i], NULL);
323326
hashtab_destroy(p->symtab[i].table);
327+
}
324328
return rc;
325329
}
326330

0 commit comments

Comments
 (0)