Il 03/08/2011 15:43, Roberto De Ioris ha scritto:

Il giorno 03/ago/2011, alle ore 15:37, Riccardo Magliocchetti ha scritto:

Hello,

cppcheck reports that buf is leaked at utils.c:2735. After some code review it 
looks it is right and the same bug is there on linux too.

It happens only once at startup time so no big deal but still.

Checked that uwsgicc still loads fine after the patch, cannot test other 
platforms. Please review.


Cannot be freed as its pointer will be mapped to uwgsi.binary_path that must be 
available for the whole server life-cycle.

Is there a way to mark this kind of allocation to make cppcheck happy ?

You are right for the linux hunk, the sun one looks not correct because we are not supposed to free what it returns, the man page does not say to do so, looked at java and mesa source code and they copy it to a buffer. So i've reworked a patch to free buf in the case we return argvzero on linux and on freebsd.

With the patch applied cppcheck is fine.

thanks,
riccardo
diff -r 2f5831450427 utils.c
--- a/utils.c	Wed Aug 03 15:07:15 2011 +0200
+++ b/utils.c	Wed Aug 03 16:09:43 2011 +0200
@@ -2692,6 +2692,8 @@
 	ssize_t len = readlink("/proc/self/exe", buf, uwsgi.page_size);
 	if (len > 0) {
 		return buf;
+	} else {
+		free(buf);
 	}
 #elif defined(__APPLE__)
 	char *buf = uwsgi_malloc(uwsgi.page_size);
@@ -2715,9 +2717,9 @@
 		}
 		char *newbuf = realpath(buf, NULL);
 		if (newbuf) {
-			return newbuf;	
+			return newbuf;
 		}
-	}	
+	}
 #elif defined(__FreeBSD__)
 	char *buf = uwsgi_malloc(uwsgi.page_size);
 	size_t len = uwsgi.page_size;
@@ -2729,6 +2731,7 @@
 	if (sysctl(mib, 4, buf, &len, NULL, 0) == 0) {
 		return buf;
 	}
+	free(buf);
 #endif
 
 
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to