[project @ 2003-11-05 09:58:01 by simonmar]
authorsimonmar <unknown>
Wed, 5 Nov 2003 09:58:01 +0000 (09:58 +0000)
committersimonmar <unknown>
Wed, 5 Nov 2003 09:58:01 +0000 (09:58 +0000)
Fix a memory leak in __hscore_readdir() which meant that one struct
dirent was leaked at the end of each directory read.

Bug-reported-by: David Roundy <droundy@abridgegame.org>
What-a-great-system: Valgrind

cbits/dirUtils.c

index 4422440..f256463 100644 (file)
@@ -81,7 +81,11 @@ __hscore_readdir( HsAddr dirPtr, HsAddr pDirEnt )
   if (p == NULL) return -1;
   res = readdir_r((DIR*)dirPtr, p, pDirE);
   if (res != 0) {
-    *pDirE = NULL;
+      *pDirE = NULL;
+      free(p);
+  }
+  else if (*pDirE == NULL) {
+    // end of stream
     free(p);
   }
   return res;