Skip to contentSkip to conversation

Fix memory textfile_get() memory leaks

PATCH In review Ville Nuorvala 2 participants 5 messages Sep 7, 2005 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix memory textfile_get() memory leaks

Hi,

there apparently are a couple of places where the bluez-utils is leaking memory after calling textfile_get(). The patch below should fix this...

Index: hcid/storage.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/storage.c,v
retrieving revision 1.24

storage.c 7 Sep 2005 11:23:14 -0000 renamed from storage.c 30 Aug 2005 00:35:39 -0000 1.24 +5 -0
diff -u -r1.24 storage.c
@@ -87,6 +87,8 @@
                str[248] = '\0';
        strcpy(name, str);
 
+       free(str);
+
        return 0;
 }
 
@@ -161,6 +163,7 @@
                memcpy(tmp, str + (i * 2), 2);
                key[i] = (uint8_t) strtol(tmp, NULL, 16);
        }
+       free(str);
 
        return 0;
 }
@@ -181,5 +184,7 @@
        strncpy(pin, str, 16);
        len = strlen(pin);
 
+       free(str);
+
        return len;
 }

Index: common/test_textfile.c
===================================================================
RCS file: /cvsroot/bluez/utils/common/test_textfile.c,v retrieving revision 1.2

test_textfile.c 7 Sep 2005 11:23:14 -0000 renamed from test_textfile.c 6 Aug 2005 06:27:40 -0000 1.2 +2 -0
diff -u -r1.2 test_textfile.c
@@ -64,6 +64,8 @@
                str = textfile_get(filename, key);
                if (!str)
                        fprintf(stderr, "No value for %s\n", key);
+               else
+                       free(str);
        }
 
        return 0;

Regards,
Ville

Signature · 16 lines
Ville Nuorvala
Research Assistant,
Laboratory for Theoretical Computer Science,
Helsinki University of Technology
email: [email protected], phone: +358 (0)9 451 5257


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
maintainer
#1 lore raw

Hi Ville,

Quoted 2 lines

there apparently are a couple of places where the bluez-utils is leaking memory after calling textfile_get(). The patch below should fix this...

coding style, coding style, coding style !!!

We use tabs instead of whitespaces. This means your patch is wrong or your mailer screwed it up.

Regards

Marcel

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#2 lore raw
Quoted 10 lines · Marcel Holtmann

Hi Ville,

Quoted 1 line

there apparently are a couple of places where the bluez-utils is leaking memory after calling textfile_get(). The patch below should fix this...

coding style, coding style, coding style !!!

We use tabs instead of whitespaces. This means your patch is wrong or your mailer screwed it up.

Sorry, the tabs got screwed up. The attached patch should be acceptable.

Regards,
Ville

Signature · 5 lines
Ville Nuorvala
Research Assistant,
Laboratory for Theoretical Computer Science,
Helsinki University of Technology
email: [email protected], phone: +358 (0)9 451 5257

Index: hcid/storage.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/storage.c,v
retrieving revision 1.24

storage.c +5 -0
diff -u -r1.24 storage.c
@@ -87,6 +87,8 @@
 		str[248] = '\0';
 	strcpy(name, str);
 
+	free(str);
+
 	return 0;
 }
 
@@ -161,6 +163,7 @@
 		memcpy(tmp, str + (i * 2), 2);
 		key[i] = (uint8_t) strtol(tmp, NULL, 16);
 	}
+	free(str);
 
 	return 0;
 }
@@ -181,5 +184,7 @@
 	strncpy(pin, str, 16);
 	len = strlen(pin);
 
+	free(str);
+
 	return len;
 }

Index: common/test_textfile.c
===================================================================
RCS file: /cvsroot/bluez/utils/common/test_textfile.c,v retrieving revision 1.2

test_textfile.c +2 -0
diff -u -r1.2 test_textfile.c
@@ -64,6 +64,8 @@
 		str = textfile_get(filename, key);
 		if (!str)
 			fprintf(stderr, "No value for %s\n", key);
+		else
+			free(str);
 	}
 
 	return 0;
#3 lore raw

Sorry, I forgot to include stdlib.h in test_textfile.c. Please use this updated patch file...

Regards,
Ville

Signature · 5 lines
Ville Nuorvala
Research Assistant,
Laboratory for Theoretical Computer Science,
Helsinki University of Technology
email: [email protected], phone: +358 (0)9 451 5257

Index: hcid/storage.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/storage.c,v
retrieving revision 1.24

storage.c +5 -0
diff -u -r1.24 storage.c
@@ -87,6 +87,8 @@
 		str[248] = '\0';
 	strcpy(name, str);
 
+	free(str);
+
 	return 0;
 }
 
@@ -161,6 +163,7 @@
 		memcpy(tmp, str + (i * 2), 2);
 		key[i] = (uint8_t) strtol(tmp, NULL, 16);
 	}
+	free(str);
 
 	return 0;
 }
@@ -181,5 +184,7 @@
 	strncpy(pin, str, 16);
 	len = strlen(pin);
 
+	free(str);
+
 	return len;
 }

Index: common/test_textfile.c
===================================================================
RCS file: /cvsroot/bluez/utils/common/test_textfile.c,v retrieving revision 1.2

test_textfile.c +3 -1
diff -u -r1.2 test_textfile.c
@@ -35,7 +35,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
-
+#include <stdlib.h>
 #include "textfile.h"
 
 int main(int argc, char *argv[])
@@ -64,6 +64,8 @@
 		str = textfile_get(filename, key);
 		if (!str)
 			fprintf(stderr, "No value for %s\n", key);
+		else
+			free(str);
 	}
 
 	return 0;
maintainer
#4 lore raw

Hi Ville,

Quoted 2 lines

Sorry, I forgot to include stdlib.h in test_textfile.c. Please use this updated patch file...

ok, this one is now in the CVS. Thanks for looking at it. More fixes for memory leaks are welcome ;)

Regards

Marcel

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel