libsepol: Fix memory leak in role_dominates_copy_callback
PATCH 1/1 libsepol: Fix memory leak in role_dominates_copy_callback
Free memory allocated by map_ebitmap in case ebitmap_union fails.
Fixes:
Defect type: RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2: alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node". libsepol-3.10/src/expand.c:68:3: alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node". libsepol-3.10/src/ebitmap.c:420:2: alloc_fn: Storage is returned from allocation function "malloc". libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t *)malloc(24UL)". libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3: leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.
\# 829| return -1; \# 830| if (ebitmap_union(&new_role->dominates, &mapped)) \# 831|-> return -1; \# 832| ebitmap_destroy(&mapped); \# 833| --- libsepol/src/expand.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/src/expand.c +3 -1
@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unusedif (map_ebitmap (&role->dominates, &mapped, state->rolemap))return -1 ; -if (ebitmap_union (&new_role->dominates, &mapped)) +if (ebitmap_union (&new_role->dominates, &mapped)) { +ebitmap_destroy (&mapped);return -1 ; + }ebitmap_destroy (&mapped);return 0 ;
Signature · 1 line
2.52.0
Quoted 10 lines · Vit Mojzis
Free memory allocated by
map_ebitmapin caseebitmap_unionfails.Fixes:
Defect type:RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2:alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node".libsepol-3.10/src/expand.c:68:3:alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node".libsepol-3.10/src/ebitmap.c:420:2:alloc_fn: Storage is returned from allocation function "malloc".libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t*)malloc(24UL)".libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3:leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.
Quoted 6 lines
\# 829| return -1; \# 830| if (ebitmap_union(&new_role->dominates, &mapped)) \# 831|-> return -1; \# 832| ebitmap_destroy(&mapped); \# 833|
Missing Signed-of-by tag.
Quoted 22 lines
--- libsepol/src/expand.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)libsepol/src/expand.c +3
-1@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unusedif (map_ebitmap (&role->dominates, &mapped, state->rolemap))return -1 ; -if (ebitmap_union (&new_role->dominates, &mapped)) +if (ebitmap_union (&new_role->dominates, &mapped)) { +ebitmap_destroy (&mapped);return -1 ; + }ebitmap_destroy (&mapped);return 0 ;Signature · 1 line
2.52.0
PATCH v2 1/1 libsepol: Fix memory leak in role_dominates_copy_callback
Free memory allocated by map_ebitmap in case ebitmap_union fails.
Fixes:
Defect type: RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2: alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node". libsepol-3.10/src/expand.c:68:3: alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node". libsepol-3.10/src/ebitmap.c:420:2: alloc_fn: Storage is returned from allocation function "malloc". libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t *)malloc(24UL)". libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3: leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.
\# 829| return -1; \# 830| if (ebitmap_union(&new_role->dominates, &mapped)) \# 831|-> return -1; \# 832| ebitmap_destroy(&mapped); \# 833|
---
No changes, only added "Signed-off-by".
libsepol/src/expand.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
libsepol/src/expand.c +3 -1
@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unusedif (map_ebitmap (&role->dominates, &mapped, state->rolemap))return -1 ; -if (ebitmap_union (&new_role->dominates, &mapped)) +if (ebitmap_union (&new_role->dominates, &mapped)) { +ebitmap_destroy (&mapped);return -1 ; + }ebitmap_destroy (&mapped);return 0 ;
Signature · 1 line
2.53.0
Quoted 10 lines · Vit Mojzis
Free memory allocated by
map_ebitmapin caseebitmap_unionfails.Fixes:
Defect type:RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2:alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node".libsepol-3.10/src/expand.c:68:3:alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node".libsepol-3.10/src/ebitmap.c:420:2:alloc_fn: Storage is returned from allocation function "malloc".libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t*)malloc(24UL)".libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3:leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.
Quoted 7 lines
\# 829| return -1; \# 830| if (ebitmap_union(&new_role->dominates, &mapped)) \# 831|-> return -1; \# 832| ebitmap_destroy(&mapped); \# 833|Signed-off-by Vit Mojzis <[email protected]>
Quoted 24 lines
---
No changes, only added "Signed-off-by".libsepol/src/expand.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)libsepol/src/expand.c +3
-1@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unusedif (map_ebitmap (&role->dominates, &mapped, state->rolemap))return -1 ; -if (ebitmap_union (&new_role->dominates, &mapped)) +if (ebitmap_union (&new_role->dominates, &mapped)) { +ebitmap_destroy (&mapped);return -1 ; + }ebitmap_destroy (&mapped);return 0 ;Signature · 1 line
2.53.0
Quoted 19 lines · Petr Lautrbach
Quoted 16 lines · Vit Mojzis
Free memory allocated by
map_ebitmapin caseebitmap_unionfails.Fixes:
Defect type:RESOURCE_LEAK
libsepol-3.10/src/expand.c:828:2:alloc_arg: "map_ebitmap" allocates memory that is stored into "mapped.node".libsepol-3.10/src/expand.c:68:3:alloc_arg: "ebitmap_set_bit" allocates memory that is stored into "dst->node".libsepol-3.10/src/ebitmap.c:420:2:alloc_fn: Storage is returned from allocation function "malloc".libsepol-3.10/src/ebitmap.c:420:2: assign: Assigning: "new" = "(ebitmap_node_t*)malloc(24UL)".libsepol-3.10/src/ebitmap.c:437:3: assign: Assigning: "e->node" = "new".
libsepol-3.10/src/expand.c:831:3:leaked_storage: Variable "mapped" going out of scope leaks the storage "mapped.node" points to.\# 829| return -1; \# 830| if (ebitmap_union(&new_role->dominates, &mapped)) \# 831|-> return -1; \# 832| ebitmap_destroy(&mapped); \# 833|
Quoted 4 lines
Quoted 1 line
Signed-off-by Vit Mojzis <[email protected]>Acked-by Petr Lautrbach <[email protected]>
Merged.
Thanks,
Jim
Quoted 26 lines
Quoted 24 lines
---
No changes, only added "Signed-off-by".libsepol/src/expand.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)libsepol/src/expand.c +3
-2@@ -827,8 +827,10 @@ static int role_dominates_copy_callback(hashtab_key_t key __attribute__ ((unusedif (map_ebitmap (&role->dominates, &mapped, state->rolemap))return -1 ; -if (ebitmap_union (&new_role->dominates, &mapped)) +if (ebitmap_union (&new_role->dominates, &mapped)) { +ebitmap_destroy (&mapped);return -1 ; + }ebitmap_destroy (&mapped);return 0 ; --2.53.0