From 0c5b32919e64e2fbdfd26e900f06eb29f47fc295 Mon Sep 17 00:00:00 2001 From: Genta IHA Date: Mon, 15 Jan 2018 18:17:20 +0900 Subject: vyatta-cfg: Fix memory leak in Cstore perl binding The Cstore perl binding (XS) has memory leak bug. This commit will fix this issue. All XS should implement "DESTROY" function to free memory, but this binding haven't this function. It leads memory leak each time when you call "new Cstore();" in perl code. Additionally, VyOS Helium standard Perl module "Vyatta::Config" have a Cstore instance variable, and each time calling "new Vyatta::Config();" in Perl causes memory leak due to this issue. Especially, the long-live process using Vyatta::Config (e.g. vyos-intfwatched) lead to serious memory exhaustion problem due to this issue. This patch implements the "DESTROY" function in XS for Cstore library, and fix this memory leak issue. --- perl_dmod/Cstore/Cstore.xs | 4 ++++ perl_dmod/Cstore/typemap | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/perl_dmod/Cstore/Cstore.xs b/perl_dmod/Cstore/Cstore.xs index 3c9a9ad..3626303 100644 --- a/perl_dmod/Cstore/Cstore.xs +++ b/perl_dmod/Cstore/Cstore.xs @@ -45,6 +45,10 @@ OUTPUT: RETVAL +void +Cstore::DESTROY() + + bool Cstore::cfgPathExists(CPATH *pref, bool active_cfg) PREINIT: diff --git a/perl_dmod/Cstore/typemap b/perl_dmod/Cstore/typemap index 8d6d178..7714cd1 100644 --- a/perl_dmod/Cstore/typemap +++ b/perl_dmod/Cstore/typemap @@ -12,7 +12,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -Cstore * O_CPPOBJ +Cstore * O_OBJECT STRVEC * T_STRVEC_REF CPATH * T_CPATH_REF STRSTRMAP * T_STRSTRMAP_REF @@ -20,7 +20,7 @@ STRSTRMAP * T_STRSTRMAP_REF ############################################################ OUTPUT -O_CPPOBJ +O_OBJECT sv_setref_pv($arg, CLASS, (void *) $var); T_STRVEC_REF @@ -44,7 +44,7 @@ T_STRSTRMAP_REF ############################################################ INPUT -O_CPPOBJ +O_OBJECT if (sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG)) { $var = ($type) SvIV((SV *) SvRV($arg)); } else { -- cgit v1.2.3