getpwnam_error:
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:11 +0200
changeset 33 5e0a954f7c0b
parent 32 9b56360ec64e
child 34 4a35f239fe5b
getpwnam_error: * getpwnam allocates memory for the struct and there is no way to free it. * it seems to be a bug in the library function. committer: Markus Bröker <mbroeker@largo.homelinux.org>
Makefile
getpwnam_error.c
--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,8 @@
 	function_pointers \
 	sort \
 	min2time \
-	recursive_compiler
+	recursive_compiler \
+	getpwnam_error
 
 .SUFFIXES: .c .cc .asm
 
@@ -240,6 +241,10 @@
 	@echo Linking $< ...
 	@$(CC) -o $@ $<
 
+getpwnam_error: getpwnam_error.o
+	@echo Linking $< ...
+	@$(CC) -o $@ $<
+
 .PHONY: clean uninstall
 
 clean:
new file mode 100644
--- /dev/null
+++ b/getpwnam_error.c
@@ -0,0 +1,56 @@
+/**
+ * test/demos/getpwnam_error.c
+ * Copyright (C) 2008 Markus Broeker
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <pwd.h>
+
+/**
+==7531==
+==7531== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 25 from 2)
+==7531== malloc/free: in use at exit: 156 bytes in 11 blocks.
+==7531== malloc/free: 66 allocs, 55 frees, 6,342 bytes allocated.
+==7531== For counts of detected errors, rerun with: -v
+==7531== searching for pointers to 11 not-freed blocks.
+==7531== checked 60,444 bytes.
+==7531==
+==7531== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 1 of 3
+==7531==    at 0x4022D6E: malloc (vg_replace_malloc.c:207)
+==7531==    by 0x412C7E0: (within /lib/i686/cmov/libc-2.7.so)
+==7531==    by 0x412D0DB: __nss_database_lookup (in /lib/i686/cmov/libc-2.7.so)
+==7531==    by 0x4596F5B: ???
+==7531==    by 0x4597CF6: ???
+==7531==    by 0x40D3BD1: getpwnam_r (in /lib/i686/cmov/libc-2.7.so)
+==7531==    by 0x40D3646: getpwnam (in /lib/i686/cmov/libc-2.7.so)
+==7531==    by 0x8048478: main (getpwnam_error.c:48)
+==7531==
+==7531== LEAK SUMMARY:
+==7531==    definitely lost: 36 bytes in 1 blocks.
+==7531==    indirectly lost: 120 bytes in 10 blocks.
+==7531==      possibly lost: 0 bytes in 0 blocks.
+==7531==    still reachable: 0 bytes in 0 blocks.
+==7531==         suppressed: 0 bytes in 0 blocks.
+*/
+
+int main (int argc, char **argv)
+{
+    struct passwd *pwd;
+    char *user;
+
+    if ((user = getenv ("USER")) == NULL) {
+        printf ("This system isn't supported yet\n");
+        return EXIT_FAILURE;
+    }
+
+    if ((pwd = getpwnam (user)) == NULL) {
+        printf ("I wasn't able to retrieve the neccessary data\n");
+        return EXIT_FAILURE;
+    }
+
+    printf ("Your full name: %s\n", pwd->pw_gecos);
+
+    return EXIT_SUCCESS;
+}