[vdr] 1.3.22: memory leaks

Stefan Huelswitt s.huelswitt at gmx.de
Sun Mar 27 11:07:49 CEST 2005


Hi,
while investigating VDR with valgrind and other memory tracing
tools, I found two places where memory leaks.

First is in dvbplayer.c, where the Action() code builds a frame
from the replayed file (readFrame). If the ringbuffer is already
full, this frame cannot be put immediately. If Empty() is called
in such a situation, the premade frame is lost.
Solution:

--- dvbplayer.c	2005-01-14 15:00:56.000000000 +0100
+++ dvbplayer.c	2005-03-26 21:41:23.000000000 +0100
@@ -296,6 +296,7 @@
      nonBlockingFileReader->Clear();
   if ((readIndex = backTrace->Get(playDir == pdForward)) < 0)
      readIndex = writeIndex;
+  delete readFrame;
   readFrame = NULL;
   playFrame = NULL;
   ringBuffer->Clear();

Second is in epg.c tComponent::FromString(). I cannot find
anything bad with the code there, but valgrind reports a lot of
memory leaks with the sscanf() call. So I guessed that sscanf() is
leaking internaly when used with "%a[\n]" (at least with my glibc
version 2.2.5). After changing to code to the suggestion below,
the leaks disappeared:

--- epg.c	2005-02-19 12:35:00.000000000 +0100
+++ epg.c	2005-03-27 10:53:06.000000000 +0200
@@ -28,13 +28,12 @@
 bool tComponent::FromString(const char *s)
 {
   unsigned int Stream, Type;
-  int n = sscanf(s, "%X %02X %3c %a[^\n]", &Stream, &Type, language, &description);
-  if (n != 4)
+  char buf[512];
+  int n = sscanf(s, "%X %02X %3c %511[^\n]", &Stream, &Type, language, buf);
+  if (n==4 && !isempty(buf))
+     description = strdup(buf);
+  else
      description = NULL;
-  else if (isempty(description)) {
-     free(description);
-     description = NULL;
-     }
   stream = Stream;
   type = Type;
   return n >= 3;

Regards.

-- 
Stefan Huelswitt
s.huelswitt at gmx.de  | http://www.muempf.de/



More information about the vdr mailing list