Skip to content

Commit 4538523

Browse files
WOnder93pcmoore
authored andcommitted
selinux: fix memory leak in policydb_init()
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: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent acbc372 commit 4538523

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

security/selinux/ss/policydb.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)
274274
return v;
275275
}
276276

277+
static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap);
278+
277279
/*
278280
* Initialize a policy database structure.
279281
*/
@@ -321,8 +323,10 @@ static int policydb_init(struct policydb *p)
321323
out:
322324
hashtab_destroy(p->filename_trans);
323325
hashtab_destroy(p->range_tr);
324-
for (i = 0; i < SYM_NUM; i++)
326+
for (i = 0; i < SYM_NUM; i++) {
327+
hashtab_map(p->symtab[i].table, destroy_f[i], NULL);
325328
hashtab_destroy(p->symtab[i].table);
329+
}
326330
return rc;
327331
}
328332

0 commit comments

Comments
 (0)