Hi!
While checking some plugins with valgrind, I stumbled across this minor bug in vdr:
The skinDescriptions array allocated in cMenuSetupOsd should be deleted with delete[] instead of delete.
bye,
Tobias
--- vdr-1.4.0.orig/menu.c +++ vdr-1.4.0/menu.c @@ -2131,7 +2131,7 @@ cMenuSetupOSD::~cMenuSetupOSD() { cFont::SetCode(I18nCharSets()[Setup.OSDLanguage]); - delete skinDescriptions; + delete[] skinDescriptions; }
void cMenuSetupOSD::Set(void)
On Sun, May 21, 2006 at 06:32:23PM +0200, Tobias Grimm wrote:
Hello,
While checking some plugins with valgrind, I stumbled across this minor bug in vdr:
That's great, is there a "tutorial" for using valgrind ?
I have a "quiete patched" vdr which produce : *** glibc detected *** corrupted double-linked list: 0x000000000071b510 ***
Thank you very much,
Gregoire Favre wrote:
That's great, is there a "tutorial" for using valgrind ?
See here:
http://www.cprogramming.com/debugging/valgrind.html http://valgrind.org/
for the Debian vdr packages in my repository (sorry, german only) : http://www.e-tobi.net/blog/articles/2006/04/30/speicherlecks-im-vdr-finden
Debugging a vdr plugin with valgrind is a little bit tricky, because the symbols get lost, when VDR unloads the plugins. That's why I've built a small patch for the Debian vdr debug package. With this patch, you can force VDR to keep the plugin libs loaded with the options -k or --keep-plugins.
I've attached the patch to this mail.
Don't forget to compile VDR and the plugins with debugging informaton ( -g ) and without optimization (-O0) - and don't strip the symbols from the binary!
bye,
Tobias
Tobias Grimm wrote:
I've attached the patch to this mail.
Ooops... forgot that :-)
To enable the patch, you must define VDRDEBUG.
Tobias
#! /bin/sh /usr/share/dpatch/dpatch-run ## 82_valgrind.dpatch by Debian VDR Team pkg-vdr-dvb-devel@lists.alioth.debian.org ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: No description.
@DPATCH@ diff -urNad vdr-1.3.49~/plugin.c vdr-1.3.49/plugin.c --- vdr-1.3.49~/plugin.c 2006-04-17 11:20:05.000000000 +0200 +++ vdr-1.3.49/plugin.c 2006-05-01 12:17:01.000000000 +0200 @@ -144,6 +144,10 @@
// --- cDll ------------------------------------------------------------------
+#ifdef VDRDEBUG +bool cDll::keepPlugins = false; +#endif + cDll::cDll(const char *FileName, const char *Args) { fileName = strdup(FileName); @@ -155,8 +159,16 @@ cDll::~cDll() { delete plugin; +#ifdef VDRDEBUG + if (!keepPlugins) + { + if (handle) + dlclose(handle); + } +#else if (handle) dlclose(handle); +#endif free(args); free(fileName); } diff -urNad vdr-1.3.49~/plugin.h vdr-1.3.49/plugin.h --- vdr-1.3.49~/plugin.h 2006-04-17 11:18:16.000000000 +0200 +++ vdr-1.3.49/plugin.h 2006-05-01 12:16:44.000000000 +0200 @@ -67,6 +67,9 @@ void *handle; cPlugin *plugin; public: + #ifdef VDRDEBUG + static bool keepPlugins; + #endif cDll(const char *FileName, const char *Args); virtual ~cDll(); bool Load(bool Log = false); diff -urNad vdr-1.3.49~/vdr.c vdr-1.3.49/vdr.c --- vdr-1.3.49~/vdr.c 2006-05-01 12:13:12.000000000 +0200 +++ vdr-1.3.49/vdr.c 2006-05-01 12:17:12.000000000 +0200 @@ -213,6 +213,9 @@ { "epgfile", required_argument, NULL, 'E' }, { "grab", required_argument, NULL, 'g' }, { "help", no_argument, NULL, 'h' }, +#ifdef VDRDEBUG + { "keep-plugins", no_argument, NULL, 'k' }, +#endif { "lib", required_argument, NULL, 'L' }, { "lirc", optional_argument, NULL, 'l' | 0x100 }, { "log", required_argument, NULL, 'l' }, @@ -233,7 +236,7 @@ };
int c; - while ((c = getopt_long(argc, argv, "a:c:dD:E:g:hl:L:mp:P:r:s:t:u:v:Vw:", long_options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "a:c:dD:E:g:hkl:L:mp:P:r:s:t:u:v:Vw:", long_options, NULL)) != -1) { switch (c) { case 'a': AudioCommand = optarg; break; @@ -256,6 +259,10 @@ break; case 'h': DisplayHelp = true; break; +#ifdef VDRDEBUG + case 'k': cDll::keepPlugins = true; + break; +#endif case 'l': { char *p = strchr(optarg, '.'); if (p) @@ -385,6 +392,9 @@ " existing directory, without any "..", double '/'\n" " or symlinks (default: none, same as -g-)\n" " -h, --help print this help and exit\n" +#ifdef VDRDEBUG + " -k --keep-plugins Support valgrind by not unloading plugins\n" +#endif " -l LEVEL, --log=LEVEL set log level (default: 3)\n" " 0 = no logging, 1 = errors only,\n" " 2 = errors and info, 3 = errors, info and debug\n"
On Wed, May 24, 2006 at 07:42:21PM +0200, Tobias Grimm wrote:
Don't forget to compile VDR and the plugins with debugging informaton ( -g ) and without optimization (-O0) - and don't strip the symbols from the binary!
Hello,
very very interesting !!!
(Un)fortunately, without -O3 my VDR don't crash anymore : -O2 is perfect !!!
Thank you very much,
Gregoire Favre gregoire.favre@gmail.com wrote:
On Wed, May 24, 2006 at 07:42:21PM +0200, Tobias Grimm wrote:
Don't forget to compile VDR and the plugins with debugging informaton ( -g ) and without optimization (-O0) - and don't strip the symbols from the binary!
(Un)fortunately, without -O3 my VDR don't crash anymore : -O2 is perfect !!!
sounds as you are overrunning memory somewhere (off by one error). you can ofcourse use valgrind and gdb even on optimized code, but they work better when not optimizing.
clemens