Mailing List archive

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

[vdr] vdr 1.3.19: memory leak in AddDirectory



Hi,
I noticed that there is a memory leak in AddDirectory().
The functions uses asprint() to malloc the new directory string,
but on exit this string is strdup'ed by cString and the malloc'ed
buffer is lost.

The attached patch fixes the problem. If a static sized buffer is
not acceptable, we would have to use something like:

char buf[strlen(DirName)+strlen(FileName)+3];

But it seems that gcc 2.95.x cannot handle this correctly, at
least not with -O2.

There is a similiar memory leak in strescape(), but I don't see a
easy way to resolv this.

Regards.

-- 
Stefan Huelswitt
s.huelswitt@gmx.de  | http://www.muempf.de/
--- vdr-1.3.19-orig/tools.c	2005-01-16 12:47:44.000000000 +0100
+++ vdr-1.3.19/tools.c	2005-02-04 19:02:17.000000000 +0100
@@ -248,8 +248,8 @@
 
 cString AddDirectory(const char *DirName, const char *FileName)
 {
-  char *buf;
-  asprintf(&buf, "%s/%s", DirName && *DirName ? DirName : ".", FileName);
+  char buf[PATH_MAX];
+  snprintf(buf, sizeof(buf), "%s/%s", DirName && *DirName ? DirName : ".", FileName);
   return buf;
 }
 

Home | Main Index | Thread Index