From: Ivan Gyurdiev <ivg2@cornell.edu>
To: selinux@tycho.nsa.gov
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Subject: [ SEPOL 3 ] Fix MLS memory leaks: interfaces/ports/users
Date: Wed, 26 Oct 2005 01:06:17 -0400 [thread overview]
Message-ID: <435F0EC9.5010407@cornell.edu> (raw)
[-- 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;
}
next reply other threads:[~2005-10-26 5:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-26 5:06 Ivan Gyurdiev [this message]
2005-10-26 5:07 ` [ SEPOL 3 ] Fix MLS memory leaks: interfaces/ports/users Ivan Gyurdiev
2005-10-26 13:33 ` Stephen Smalley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=435F0EC9.5010407@cornell.edu \
--to=ivg2@cornell.edu \
--cc=sds@tycho.nsa.gov \
--cc=selinux@tycho.nsa.gov \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.