Re: [ROOT] Mismached new [] delete in TApplication Constructor/Destructor

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Thu Aug 01 2002 - 17:22:02 MEST


Now fixed. Thanks.

-- Fons



On Thu, 2002-08-01 at 13:32, Birger Koblitz wrote:
> Hi,
> 
> when debuggin my own program I found the following problem in
> TApplication (pro-version of root):
> ==27774== Mismatched free() / delete / delete []
> ==27774==    at 0x40047606: __builtin_delete (vg_clientfuncs.c:186)
> ==27774==    by 0x408CE03A: TApplication::~TApplication(void) (in
> /afs/desy.de/products/ROOT/3.02_07-rfdc/gcc-2.95.3/root/lib/libCore.so)
> ==27774==    by 0x804B537: main (i386_linux24/../clusters_ods.C:147)
> ==27774==    by 0x41622C5F: __libc_start_main (in /lib/libc.so.6)
> ==27774==    Address 0x46B8105C is 0 bytes inside a block of size 13
> alloc'd
> ==27774==    at 0x400474A8: __builtin_vec_new (vg_clientfuncs.c:152)
> ==27774==    by 0x4090B8B0: StrDup(char const *) (in
> /afs/desy.de/products/ROOT/3.02_07-rfdc/gcc-2.95.3/root/lib/libCore.so)
> ==27774==    by 0x408CDD0F: TApplication::TApplication(char const *, int
> *, char **, void *, int) (in
> /afs/desy.de/products/ROOT/3.02_07-rfdc/gcc-2.95.3/root/lib/libCore.so)
> ==27774==    by 0x804AB2A: main
> (/products/gcc-2.95/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/iostream.h:106)
> 
> This is due to the use of
> ./base/inc/TString.h:extern char *StrDup(const char *str); //duplicate
>                                               // str, free with delete []
> in the lines
>     for (int i = 0; i < fArgc; i++)
>       fArgv[i] = StrDup(argv[i]);
> of the constructor of TApplication with a corresponding
>    for (int i = 0; i < fArgc; i++)
>       SafeDelete(fArgv[i]);
> in the Destructor which is actually a
> ./base/inc/RConfig.h:#define SafeDelete(p) { if (p) { delete p; p = 0;
> } }
> 
> So instead of SafeDelete something like
>   if(fArgv[i]) delete [] fArgv[i];
> should be used.
> 
> Cheers,
>   Birger
> 
>  ------------------------------------------------------------
>  Birger Koblitz   koblitz@mail.desy.de  ("-/")_.-'"-._
>  MPI für Physik                          . . ; -._    )-;-,_)
>  c/o DESY-FH1     Tel. (40) 8998-3971   (v_,)'  _  )-.\  -'
>  Notkestr. 85                          _.- _..-_/ / ((.'
>  D-22603  HAMBURG                    ((,.-'   ((,/
> 
> 
> 
-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:02 MET