Alle giovedì 30 agosto 2012, Svante Signell ha scritto: > 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? > > [...] > - char fname[PATH_MAX]; > + char *fname = NULL; > + int len = 0; > IServiceManager* servmgr = XPLC_getServiceManager(); > - 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); Just realloc the fname buffer if the new len is greater than the old one (which needs to be saved), otherwise the current patch just does an inefficient malloc/free job every iteration which (most probably upstream won't like). -- Pino Toscano
Description: This is a digitally signed message part.