help-gsl
[Top][All Lists]
Advanced

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

[Help-gsl] Possible leak in gsl_multifit_fdfsolver.


From: Eduardo Novaes Hering
Subject: [Help-gsl] Possible leak in gsl_multifit_fdfsolver.
Date: Sun, 6 Oct 2013 23:17:16 +0200

Hi.

I've been struggling with this problem for a few weeks
now, but I do not have enough experience with debugging
to be sure about what is written below.

I'll quote some simple code, which I believe you know
well:

> 51:  s = gsl_multifit_fdfsolver_alloc (T, n, p);
> 52:  gsl_multifit_fdfsolver_set (s, &f, &x.vector);
> 
> 56:  do {
> 57:     iter++;
> 58:     status = gsl_multifit_fdfsolver_iterate (s);
> 
> 64:     if (status)
> 65:       break;
> 
> 67:     status = gsl_multifit_test_delta (s->dx, s->x,
> 68:                                       1e-3, 1e-3);
> 69:  }
> 70:  while (status == GSL_CONTINUE && iter < 500);
> 
> 72:  gsl_multifit_covar (s->J, 0.0, covar);
> 
> 77:  double chi = gsl_blas_dnrm2(s->f);
> 
> 89:  for (int nN = 0; nN < nNumParameters; nN++) {
> 90:    padParameters[nN] = gsl_vector_get(s->x, nN);
> 91:  }
> 
> 93:  gsl_multifit_fdfsolver_free (s);
> 94:  gsl_matrix_free (covar);


Where, from gdb:

> (gdb) p s
> $68 = (gsl_multifit_fdfsolver *) 0x10080f270
> (gdb) p *s
> $69 = {
>   type = 0x1001b6de0, 
>   fdf = 0x7fff5fbfdbc0, 
>   x = 0x100810480, 
>   f = 0x10080f6c0, 
>   J = 0x10080f740, 
>   dx = 0x100810a00, 
>   state = 0x100810cb0
> }
> (gdb) whatis s->state
> type = void *


Now, if I step through this code, keeping an eye on 
address 0x100810cc0:

> 51      s = gsl_multifit_fdfsolver_alloc (T, n, p);
> (gdb) x 0x100810cc0
> 0x100810cc0:  0x00000000
> (gdb) s
> 52      gsl_multifit_fdfsolver_set (s, &f, &x.vector);
> (gdb) x 0x100810cc0
> 0x100810cc0:  0x00000000
> (gdb) s
> 57         iter++;
> (gdb) x 0x100810cc0
> 0x100810cc0:  0x052e3967
> (gdb) s
> 58         status = gsl_multifit_fdfsolver_iterate (s);
> (gdb) x 0x100810cc0
> 0x100810cc0:  0x052e3967
> (gdb) s 
> 64         if (status)
> (gdb) x 0x100810cc0
> 0x100810cc0:  0xa697930c
> (gdb) s
> 67         status = gsl_multifit_test_delta (s->dx, s->x,
> (gdb) x 0x100810cc0
> 0x100810cc0:  0xa697930c
> (gdb) s
> 69      }
> (gdb) x 0x100810cc0
> 0x100810cc0:  0xa697930c
> (gdb) s
> 57         iter++;
> (gdb) x 0x100810cc0
> 0x100810cc0:  0xa697930c
> (gdb) s
> 58         status = gsl_multifit_fdfsolver_iterate (s);
> (gdb) x 0x100810cc0
> 0x100810cc0:  0xa697930c
> (gdb) s
> 64         if (status)
> (gdb) x 0x100810cc0
> 0x100810cc0:  0x2d9931ef
> (gdb) s
> 67         status = gsl_multifit_test_delta (s->dx, s->x,
> (gdb) b 92
> Breakpoint 11 at 0x10000b774: file Fit.cpp, line 92.
> (gdb) c
> Continuing.

> ...

> Breakpoint 11, Fit::FitData (this=0x100810120, cXData=0x7fff5fbfded8, 
> cYData=0x7fff5fbfdea0, cYStdDevData=0x7fff5fbfde68, dStdDev=0x7fff5fbfdf60, 
> padParameters=0x100810130, nNumParameters=6) at Fit.cpp:93
> 93      gsl_multifit_fdfsolver_free (s);
> (gdb) x 0x100810cc0
> 0x100810cc0:  0x0fb668f4
> (gdb) s
> 94      gsl_matrix_free (covar);
> (gdb) x 0x100810cc0
> 0x100810cc0:  0x0fb600bb
> (gdb) s
> 96      *dStdDev = chi;
> (gdb) x 0x100810cc0
> 0x100810cc0:  0x0fb600bb

This is a completely reproductive error. The address
0x100810cc0 has a null value in all the other areas
of the code. It assumes a non null value only after
line 52 and changes its value every time status is
accessed. 

In the end, when the gsl_multifit_fdfsolver should
be freed, some trash is left in that address and
I get the following, intermittent, extremely annoying
error after I try to leave my data processing functions:

>  malloc: *** error for object 0x100810cc0: incorrect checksum for freed 
> object - object was probably modified after being freed.
> *** set a breakpoint in malloc_error_break to debug
> 
> Program received signal SIGABRT, Aborted.
> 0x00007fff88c1ad46 in __kill ()


It took me a long time to find what was happening on
that address because I wrapped the GSL code in a
class which seems to cleanup everything after its
destructor is called and, when the malloc error
happens, that address has a null value again.

I can send the complete code to whoever can help
me to understand what is going on.

Thanks a lot for your attention,

Eduardo.


Eduardo Novaes Hering, PhD (MSc, DSc).
______________________________________
address@hidden
address@hidden
address@hidden
_______________________________________

INAC/SPSMS/IMAPEC, CEA Grenoble.
17 rue des Martyrs, 38054 
Grenoble cedex 9. France.
_______________________________________

Work:   (+33)or(0) 4 58 78 35 03
Mobile: (+33)or(0) 6 59 70 60 12
Fax :   (+33)or(0) 4 38 78 50 96
Home:   (+33)or(0) 9 66 84 10 40
Skype: enhering
Twitter: @enhering
http://www.gabuleu.com/enhering
_______________________________________

        Stop buying from China 
         until Tibet is free!
_______________________________________

             "A difference 
        which makes no difference
          is not a difference."

        Mr. Spock (stardate 2822.3)
  _   _   _   _   ___   _   _   _   _
_/ \_/ \_/ \_/ \_/   \_/ \_/ \_/ \_/ \_


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail


reply via email to

[Prev in Thread] Current Thread [Next in Thread]