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

[ SEPOL 3 ] 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...
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;
 	}
 


This mailing list archive is a service of Copilot Consulting.