Mailing List archive

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

[vdr] [PATCH] Automatically cleanup exited threads to fix memory leak



I have noticed for a while that the virtual memory usage of the VDR process grows by 16Mb for each channel switch. I can see this reflected in the top "size" field for the VDR process. After a large amount of channel switches the process would exhaust all of its virtual memory allowance and need to be restarted.

I have found that the cause of this leak is that the VDR threads which are restarted when changing channels do not get cleaned up properly. The exited threads hang around until something reads the exit status, exactly analogous to "zombie" child processes.

I noticed that nowhere in the thread code do we deal with reading the thread exit status. I think the easiest fix is to just detach all the threads so that they are automatically cleaned up as soon as they finish.

The patch attached works for me with vdr-1.3.3. It probably works for 1.2.x as well, but I have not tried it.

Jon



--- thread.c~	2004-01-03 16:59:33.000000000 +0000
+++ thread.c	2004-02-07 02:09:49.488977688 +0000
@@ -199,6 +199,7 @@
      running = true;
      parentTid = pthread_self();
      pthread_create(&childTid, NULL, (void *(*) (void *))&StartThread, (void *)this);
+     pthread_detach(childTid); /* Auto-reap */
      pthread_setschedparam(childTid, SCHED_RR, 0);
      usleep(10000); // otherwise calling Active() immediately after Start() causes a "pure virtual method called" error
      }

Home | Main Index | Thread Index