diff mbox series

[4/5] libsepol: avoid leak in OOM branch

Message ID 20231109135315.44095-4-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit 5e425b4165b8
Delegated to: Petr Lautrbach
Headers show
Series [1/5] semodule_link: avoid NULL dereference on OOM | expand

Commit Message

Christian Göttsche Nov. 9, 2023, 1:53 p.m. UTC
In case the member sid_key failed to allocate, free the parent struct.

Reported by Clang Analyzer:

    module_to_cil.c:2607:9: warning: Potential leak of memory pointed to by 'item' [unix.Malloc]
     2607 |         return rc;
          |                ^~

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsepol/src/module_to_cil.c | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c
index 2d77e22a..ee22dbbd 100644
--- a/libsepol/src/module_to_cil.c
+++ b/libsepol/src/module_to_cil.c
@@ -2582,6 +2582,7 @@  static int ocontext_isid_to_cil(struct policydb *pdb, const char *const *sid_to_
 		item->sid_key = strdup(sid);
 		if (!item->sid_key) {
 			ERR(NULL, "Out of memory");
+			free(item);
 			rc = -1;
 			goto exit;
 		}