All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Gyurdiev <ivg2@cornell.edu>
To: SELinux List <SELinux@tycho.nsa.gov>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Subject: [SEMANAGE] Fix memory leak in cache error path
Date: Tue, 17 Jan 2006 12:26:40 -0700	[thread overview]
Message-ID: <43CD44F0.3090805@cornell.edu> (raw)

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

The llist-based cache() implementations leak memory in the error path - 
fix that...



[-- Attachment #2: libsemanage.cache_err_memory_leak.diff --]
[-- Type: text/x-patch, Size: 3016 bytes --]

diff -Naurp --exclude-from excludes old/libsemanage/src/database_activedb.c new/libsemanage/src/database_activedb.c
--- old/libsemanage/src/database_activedb.c	2006-01-17 09:11:06.000000000 -0700
+++ new/libsemanage/src/database_activedb.c	2006-01-17 12:15:44.000000000 -0700
@@ -44,7 +44,10 @@ static int dbase_activedb_cache(
 	if (!dbase_llist_needs_resync(handle, &dbase->llist))
 		return STATUS_SUCCESS;
 
+	/* Update cache serial */
 	dbase_llist_cache_init(&dbase->llist);
+	if (dbase_llist_set_serial(handle, &dbase->llist) < 0)
+		goto err;
 
 	/* Fetch the entire list */
 	if (ratable->read_list(handle, &records, &rcount) < 0)
@@ -57,10 +60,6 @@ static int dbase_activedb_cache(
 		rtable->free(records[i]);
 	}
 
-	/* Update cache serial */
-	if (dbase_llist_set_serial(handle, &dbase->llist) < 0)
-		goto err;
-
 	free(records);
 	return STATUS_SUCCESS;
 
@@ -68,6 +67,7 @@ static int dbase_activedb_cache(
 	ERR(handle, "could not cache active database");
 	for (; i < rcount; i++)
 		rtable->free(records[i]);
+	dbase_llist_drop_cache(&dbase->llist);
 	free(records);
 	return STATUS_ERR;
 }
diff -Naurp --exclude-from excludes old/libsemanage/src/database_file.c new/libsemanage/src/database_file.c
--- old/libsemanage/src/database_file.c	2006-01-17 11:40:12.000000000 -0700
+++ new/libsemanage/src/database_file.c	2006-01-17 12:16:19.000000000 -0700
@@ -76,7 +76,10 @@ static int dbase_file_cache(
 	if (!dbase_llist_needs_resync(handle, &dbase->llist))
 		return STATUS_SUCCESS;
 
+	/* Update cache serial */
 	dbase_llist_cache_init(&dbase->llist);
+	if (dbase_llist_set_serial(handle, &dbase->llist) < 0)
+		goto err;
 
 	if (construct_filename(handle, dbase, &fname) < 0)
 		goto err;
@@ -115,10 +118,6 @@ static int dbase_file_cache(
 
 	} while (pstatus != STATUS_NODATA);
 
-	/* Update cache serial */
-	if (dbase_llist_set_serial(handle, &dbase->llist) < 0)
-		goto err;
-
 	rtable->free(process_record);
 	parse_close(parse_info);
 	parse_release(parse_info);
@@ -130,6 +129,7 @@ static int dbase_file_cache(
 	rtable->free(process_record);
 	parse_close(parse_info);
 	parse_release(parse_info);
+	dbase_llist_drop_cache(&dbase->llist);
 	free(fname);
 	return STATUS_ERR;
 }
diff -Naurp --exclude-from excludes old/libsemanage/src/database_join.c new/libsemanage/src/database_join.c
--- old/libsemanage/src/database_join.c	2006-01-17 09:11:06.000000000 -0700
+++ new/libsemanage/src/database_join.c	2006-01-17 12:16:58.000000000 -0700
@@ -58,7 +58,10 @@ static int dbase_join_cache(
 	if (!dbase_llist_needs_resync(handle, &dbase->llist))
 		return STATUS_SUCCESS;
 	
+	/* Update cache serial */
 	dbase_llist_cache_init(&dbase->llist);
+	if (dbase_llist_set_serial(handle, &dbase->llist) < 0)
+		goto err;
 
 	/* First cache any child dbase, which must
 	 * be the first thing done when calling dbase
@@ -157,6 +160,7 @@ static int dbase_join_cache(
 	free(records2);
 	rtable->key_free(rkey);
 	rtable->free(record);
+	dbase_llist_drop_cache(&dbase->llist);
 	return STATUS_ERR;
 }
 

                 reply	other threads:[~2006-01-17 19:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=43CD44F0.3090805@cornell.edu \
    --to=ivg2@cornell.edu \
    --cc=SELinux@tycho.nsa.gov \
    --cc=sds@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.