diff --git a/CHANGES.current b/CHANGES.current index 3421669de..aa438774e 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.11 (in progress) ============================ +2016-12-18: ezralanglois + [Python, Ruby, Octave] Memory leak fix on error in std::pair wrappers. + Issue https://github.com/swig/swig/pull/851 + 2016-12-18: wsfulton Zero initialize arrays when using %array_class and %array_functions. diff --git a/Lib/octave/std_pair.i b/Lib/octave/std_pair.i index a06498bf2..2f3d4dfa4 100644 --- a/Lib/octave/std_pair.i +++ b/Lib/octave/std_pair.i @@ -69,12 +69,16 @@ value_type *vp = %new_instance(std::pair); T *pfirst = &(vp->first); int res1 = swig::asval(first, pfirst); - if (!SWIG_IsOK(res1)) + if (!SWIG_IsOK(res1)) { + %delete(vp); return res1; + } U *psecond = &(vp->second); int res2 = swig::asval(second, psecond); - if (!SWIG_IsOK(res2)) + if (!SWIG_IsOK(res2)) { + %delete(vp); return res2; + } *val = vp; return SWIG_AddNewMask(res1 > res2 ? res1 : res2); } else { diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i index da31918c8..172572bff 100644 --- a/Lib/python/std_pair.i +++ b/Lib/python/std_pair.i @@ -31,7 +31,7 @@ int res2 = swig::asval((PyObject*)second, psecond); if (!SWIG_IsOK(res2)) return res2; return res1 > res2 ? res1 : res2; - } + } } static int asval(PyObject *obj, std::pair *val) { @@ -68,10 +68,16 @@ value_type *vp = %new_instance(std::pair); T *pfirst = &(vp->first); int res1 = swig::asval((PyObject*)first, pfirst); - if (!SWIG_IsOK(res1)) return res1; + if (!SWIG_IsOK(res1)) { + %delete(vp); + return res1; + } U *psecond = &(vp->second); int res2 = swig::asval((PyObject*)second, psecond); - if (!SWIG_IsOK(res2)) return res2; + if (!SWIG_IsOK(res2)) { + %delete(vp); + return res2; + } *val = vp; return SWIG_AddNewMask(res1 > res2 ? res1 : res2); } else { @@ -82,7 +88,7 @@ int res2 = swig::asval((PyObject*)second, psecond); if (!SWIG_IsOK(res2)) return res2; return res1 > res2 ? res1 : res2; - } + } } static int asptr(PyObject *obj, std::pair **val) { diff --git a/Lib/ruby/std_pair.i b/Lib/ruby/std_pair.i index 5bea67c7c..38a4ffb9b 100644 --- a/Lib/ruby/std_pair.i +++ b/Lib/ruby/std_pair.i @@ -31,7 +31,7 @@ int res2 = swig::asval((VALUE)second, psecond); if (!SWIG_IsOK(res2)) return res2; return res1 > res2 ? res1 : res2; - } + } } static int asval(VALUE obj, std::pair *val) { @@ -63,10 +63,16 @@ value_type *vp = %new_instance(std::pair); T *pfirst = &(vp->first); int res1 = swig::asval((VALUE)first, pfirst); - if (!SWIG_IsOK(res1)) return res1; + if (!SWIG_IsOK(res1)) { + %delete(vp); + return res1; + } U *psecond = &(vp->second); int res2 = swig::asval((VALUE)second, psecond); - if (!SWIG_IsOK(res2)) return res2; + if (!SWIG_IsOK(res2)) { + %delete(vp); + return res2; + } *val = vp; return SWIG_AddNewMask(res1 > res2 ? res1 : res2); } else { @@ -77,7 +83,7 @@ int res2 = swig::asval((VALUE)second, psecond); if (!SWIG_IsOK(res2)) return res2; return res1 > res2 ? res1 : res2; - } + } } static int asptr(VALUE obj, std::pair **val) {