memory leak in broydn.h


Saul Teukolsky
09-13-2011, 02:39 PM
There are potential memory leaks in broydn.h: The second and third times that the statement
restrt=true;
gets executed, the routine returns to the statement
qr=new QRdcmp(fdjac(x,fvec));
without deleting the old qr. The fix is to replace
QRdcmp *qr;
with
QRdcmp *qr=NULL;
and insert
delete qr;
before the statement
qr=new QRdcmp(fdjac(x,fvec));

Note that this bug will not cause incorrect results to be calculated, but may cause your program to crash if broydn is called many times with these side branches being taken often.