# HG changeset patch # User John W. Eaton # Date 1458011453 14400 # Node ID ac1e50cfc9ed646ad6b0c136d2ad7f30f59d781f # Parent 822dc5a202c93266049e8a12c5a8466bb8d9812f avoid possible memory leak with fftw wisdom (bug #47372) * libinterp/dldfcn/fftw.cc (Ffftw): Save fftw wisdom string in a local std::string object before calling fftw_import_wisdom_from_string. diff -r 822dc5a202c9 -r ac1e50cfc9ed libinterp/dldfcn/fftw.cc --- a/libinterp/dldfcn/fftw.cc Mon Mar 14 13:06:59 2016 -0700 +++ b/libinterp/dldfcn/fftw.cc Mon Mar 14 23:10:53 2016 -0400 @@ -228,24 +228,22 @@ std::string arg1 = args(1).xstring_value ("fftw: WISDOM must be a string"); char *str = fftw_export_wisdom_to_string (); + std::string wisdom_str (str); + free (str); if (arg1.length () < 1) fftw_forget_wisdom (); else if (! fftw_import_wisdom_from_string (arg1.c_str ())) error ("fftw: could not import supplied WISDOM"); - retval = octave_value (std::string (str)); - - // FIXME: need to free string even if there is an exception. - free (str); + retval = octave_value (wisdom_str); } else //dwisdom getter { char *str = fftw_export_wisdom_to_string (); - retval = octave_value (std::string (str)); - - // FIXME: need to free string even if there is an exception. + std::string wisdom_str (str); free (str); + retval = octave_value (wisdom_str); } } else if (arg0 == "swisdom") @@ -260,24 +258,22 @@ std::string arg1 = args(1).xstring_value ("fftw: WISDOM must be a string"); char *str = fftwf_export_wisdom_to_string (); + std::string wisdom_str (str); + free (str); if (arg1.length () < 1) fftwf_forget_wisdom (); else if (! fftwf_import_wisdom_from_string (arg1.c_str ())) error ("fftw: could not import supplied WISDOM"); - retval = octave_value (std::string (str)); - - // FIXME: need to free string even if there is an exception. - free (str); + retval = octave_value (wisdom_str); } else //swisdom getter { char *str = fftwf_export_wisdom_to_string (); - retval = octave_value (std::string (str)); - - // FIXME: need to free string even if there is an exception. + std::string wisdom_str (str); free (str); + retval = octave_value (wisdom_str); } } else if (arg0 == "threads")