Mercurial > octave
changeset 21447:ac1e50cfc9ed
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 14 Mar 2016 23:10:53 -0400 |
parents | 822dc5a202c9 |
children | 06a2f9245a11 |
files | libinterp/dldfcn/fftw.cc |
diffstat | 1 files changed, 10 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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")