[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: xplc: FTBFS on hurd-i386 (for review)



On Thu, 2012-08-30 at 20:14 +0200, Samuel Thibault wrote:
> Svante Signell, le Thu 30 Aug 2012 19:07:19 +0200, a écrit :

> fname gets allocated at each while loop iteration, but only freed once
> later.  You need to either just free before allocating with the new
> size, or reuse the same buffer (extending it if needed).

Updated patch attached. Better?
--- a/xplc/modulemgr.cpp	2004-09-30 23:09:54.000000000 +0200
+++ b/xplc/modulemgr.cpp	2012-08-30 20:26:46.000000000 +0200
@@ -29,6 +29,12 @@
 #ifdef HAVE_STDINT_H
 # include <stdint.h>
 #endif
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
 #ifdef HAVE_LIMITS_H
 # include <limits.h>
 #endif
@@ -83,7 +89,8 @@
 #if !defined(WIN32)
   DIR* dir;
   struct dirent* ent;
-  char fname[PATH_MAX];
+  char *fname = NULL;
+  int len = 0;
   IServiceManager* servmgr = XPLC_getServiceManager();
   IModuleLoader* loader;
   ModuleNode* modules = 0;
@@ -106,7 +113,11 @@
   while((ent = readdir(dir))) {
     IModule* module;
 
-    snprintf(fname, PATH_MAX, "%s/%s", directory, ent->d_name);
+    len = strlen(directory) + 1 + strlen(ent->d_name) + 1;
+    if (fname != NULL)
+      free(fname);
+    fname = (char*)malloc(len);
+    snprintf(fname, len, "%s/%s", directory, ent->d_name);
 
     module = loader->loadModule(fname);
     if(module) {
@@ -117,6 +128,7 @@
     }
   }
 
+  free(fname);
   loader->release();
 
   closedir(dir);

Reply to: