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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 libsepol/src/module_to_cil.c | 1 +
 1 file changed, 1 insertion(+)

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;
 		}
-- 
2.42.0




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux