All of lore.kernel.org
 help / color / mirror / Atom feed
* [ SEPOL 3 ] Fix MLS memory leaks: interfaces/ports/users
@ 2005-10-26  5:06 Ivan Gyurdiev
  2005-10-26  5:07 ` Ivan Gyurdiev
  2005-10-26 13:33 ` Stephen Smalley
  0 siblings, 2 replies; 3+ messages in thread
From: Ivan Gyurdiev @ 2005-10-26  5:06 UTC (permalink / raw)
  To: selinux; +Cc: Stephen Smalley

[-- Attachment #1: Type: text/plain, Size: 528 bytes --]

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...

[-- Attachment #2: libsepol.fix_leaks.diff --]
[-- Type: text/x-patch, Size: 2211 bytes --]

diff -Naurp --exclude CVS --exclude ChangeLog --exclude direct_api.c --exclude semanage_store.c --exclude VERSION --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsepol/src/interfaces.c new/libsepol/src/interfaces.c
--- old/libsepol/src/interfaces.c	2005-10-25 20:17:53.000000000 -0400
+++ new/libsepol/src/interfaces.c	2005-10-26 00:56:49.000000000 -0400
@@ -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;
diff -Naurp --exclude CVS --exclude ChangeLog --exclude direct_api.c --exclude semanage_store.c --exclude VERSION --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsepol/src/ports.c new/libsepol/src/ports.c
--- old/libsepol/src/ports.c	2005-10-25 20:42:07.000000000 -0400
+++ new/libsepol/src/ports.c	2005-10-26 00:57:00.000000000 -0400
@@ -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;
diff -Naurp --exclude CVS --exclude ChangeLog --exclude direct_api.c --exclude semanage_store.c --exclude VERSION --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsepol/src/users.c new/libsepol/src/users.c
--- old/libsepol/src/users.c	2005-10-25 20:42:07.000000000 -0400
+++ new/libsepol/src/users.c	2005-10-26 00:52:16.000000000 -0400
@@ -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;
 	}
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ SEPOL 3 ] Fix MLS memory leaks: interfaces/ports/users
  2005-10-26  5:06 [ SEPOL 3 ] Fix MLS memory leaks: interfaces/ports/users Ivan Gyurdiev
@ 2005-10-26  5:07 ` Ivan Gyurdiev
  2005-10-26 13:33 ` Stephen Smalley
  1 sibling, 0 replies; 3+ messages in thread
From: Ivan Gyurdiev @ 2005-10-26  5:07 UTC (permalink / raw)
  To: selinux; +Cc: Stephen Smalley


> 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 majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ SEPOL 3 ] Fix MLS memory leaks: interfaces/ports/users
  2005-10-26  5:06 [ SEPOL 3 ] Fix MLS memory leaks: interfaces/ports/users Ivan Gyurdiev
  2005-10-26  5:07 ` Ivan Gyurdiev
@ 2005-10-26 13:33 ` Stephen Smalley
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Smalley @ 2005-10-26 13:33 UTC (permalink / raw)
  To: Ivan Gyurdiev; +Cc: selinux

On Wed, 2005-10-26 at 01:06 -0400, Ivan Gyurdiev wrote:
> 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.

-- 
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 majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-10-26 13:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-26  5:06 [ SEPOL 3 ] Fix MLS memory leaks: interfaces/ports/users Ivan Gyurdiev
2005-10-26  5:07 ` Ivan Gyurdiev
2005-10-26 13:33 ` Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.