Fix MLS memory leaks: interfaces/ports/users
This fixes the tricky memory leaks that I've been trying to find... There are no more sepol leaks that I'm aware of at the moment.
See, all this init/destroy stuff looks so awfully fragile to me - it's the cause for all the memory leaks, and it also complicates your error recovery sequence. I would much rather prefer a single heap-based create() vs free() function, with opaque types that are only exposed to a single type. Then I can have at least some confidence that init/destroy is being properly done everywhere...
libsepol/src/interfaces.c +2 -0
@@ -184,6 +184,8 @@ int sepol_iface_modify(else prev->next = iface;free (c->u.name); +context_destroy (&c->context[0 ]); +context_destroy (&c->context[1 ]);free (c);return STATUS_SUCCESS ;
libsepol/src/ports.c +1 -0
@@ -270,6 +270,7 @@ int sepol_port_modify( policydb->ocontexts[OCON_PORT ] = port; else prev->next = port; +context_destroy (&c->context[0 ]);free (c);return STATUS_SUCCESS ;
libsepol/src/users.c +6 -4
@@ -147,16 +147,18 @@ int sepol_user_modify(/* If it does, we will modify it */ if (usrdatum) { -role_set_destroy (&usrdatum->roles); -role_set_init (&usrdatum->roles); + +int value_cp = usrdatum->value; +user_datum_destroy (usrdatum); +user_datum_init (usrdatum); + usrdatum->value = value_cp;/* Otherwise, create a new one */ }else { usrdatum = (user_datum_t *)malloc (sizeof (user_datum_t));if (!usrdatum) goto omem; -memset (usrdatum,0 ,sizeof (user_datum_t)); -role_set_init (&usrdatum->roles); +user_datum_init (usrdatum); new =1 ; }
Quoted 2 lines
with opaque types that are only exposed to a single type.
s/"to a single type"/"in a single file"/
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 2 lines · Ivan Gyurdiev
This fixes the tricky memory leaks that I've been trying to find... There are no more sepol leaks that I'm aware of at the moment.
All 5 patches (sepol/semanage debug, sepol debug2, semanage seusers, semaange policydb cache, sepol fix leaks) merged as of libsepol 1.9.31 and libsemanage 1.3.35.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.