Skip to contentSkip to conversation

Fix memory leak on disabled selinux machines.

PATCH Daniel J Walsh 2 participants 3 messages Feb 24, 2010 – Mar 6, 2010 SELinux security module

lore
Share & tools
lore
#0 lore raw

I think this patch originally came from Eric Paris and was updated by others but has not been adopted yet. Not sure why.

Always free buf on exit.

src/init.c +8 -6
@@ -23,7 +23,7 @@
 static void init_selinuxmnt(void)
 {
 	char *buf=NULL, *p;
-	FILE *fp;
+	FILE *fp=NULL;
 	struct statfs sfbuf;
 	int rc;
 	size_t len;
@@ -57,16 +57,17 @@
 			break;
 		}
 	}
-	fclose(fp);
 
-	if (!exists)
-		return;
+	if (!exists) 
+		goto out;
+
+	fclose(fp);
 
 	/* At this point, the usual spot doesn't have an selinuxfs so
 	 * we look around for it */
 	fp = fopen("/proc/mounts", "r");
 	if (!fp)
-		return;
+		goto out;
 
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);
 	while ((num = getline(&buf, &len, fp)) != -1) {
@@ -90,7 +91,8 @@
 
       out:
 	free(buf);
-	fclose(fp);
+	if (fp)
+		fclose(fp);
 	return;
 }
 
#1 lore raw
Quoted 3 lines · Daniel J Walsh

I think this patch originally came from Eric Paris and was updated by others but has not been adopted yet. Not sure why.

Always free buf on exit.

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

#2 lore raw
Quoted 9 lines · Joshua Brindle
Quoted 4 lines · Daniel J Walsh

I think this patch originally came from Eric Paris and was updated by others but has not been adopted yet. Not sure why.

Always free buf on exit.

Merged in libselinux 2.0.92

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