diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-04-26 22:26:53 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-04-26 22:26:53 +0200 |
commit | f4f90e85fb668ddb22b5148d356a25d689bdfd08 (patch) | |
tree | ffe140592bc6b626d1cc97f6e71453302872e5de | |
parent | 2c653542269c6c1471f3944fb8be6ebbcadf2956 (diff) | |
download | weechat-f4f90e85fb668ddb22b5148d356a25d689bdfd08.zip |
perl: fix memory leak when calling perl functions (bug #32895)
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl.c | 71 |
2 files changed, 29 insertions, 43 deletions
@@ -86,6 +86,7 @@ Version 0.3.5 (under dev!) * irc: add many missing commands for target buffer (options irc.msgbuffer.xxx) (bug #32216) * lua: fix crash when many scripts are executing callbacks at same time +* perl: fix memory leak when calling perl functions (bug #32895) * relay: fix crash on /upgrade when nick in irc client is not yet set * relay: allow colon in server password received from client * relay: do not send join for private buffers to client diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index 998663f22..353cdfd3f 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -207,43 +207,6 @@ weechat_perl_hash_to_hashtable (SV *hash, int hashtable_size) } /* - * weechat_perl_exec_pv: encapsulation of call to perl_call_pv - */ - -int -weechat_perl_exec_pv (const char *func, const char *format, void **argv) -{ - int i, argc; - HV *hash; - - dSP; - - PUSHMARK(SP); - if (format && format[0]) - { - argc = strlen (format); - for (i = 0; i < argc; i++) - { - switch (format[i]) - { - case 's': /* string */ - XPUSHs(sv_2mortal(newSVpv((char *)argv[i], 0))); - break; - case 'i': /* integer */ - XPUSHs(sv_2mortal(newSViv(*((int *)argv[i])))); - break; - case 'h': /* hash */ - hash = weechat_perl_hashtable_to_hash (argv[i]); - XPUSHs(sv_2mortal((SV *)hash)); - break; - } - } - PUTBACK; - } - return perl_call_pv (func, G_EVAL | G_SCALAR); -} - -/* * weechat_perl_exec: execute a perl function */ @@ -255,16 +218,14 @@ weechat_perl_exec (struct t_plugin_script *script, char *func; unsigned int count; void *ret_value; - int *ret_i, mem_err, length; + int *ret_i, mem_err, length, i, argc; SV *ret_s; + HV *hash; struct t_plugin_script *old_perl_current_script; #ifdef MULTIPLICITY void *old_context; #endif - /* this code is placed here to conform ISO C90 */ - dSP; - old_perl_current_script = perl_current_script; perl_current_script = script; @@ -285,10 +246,33 @@ weechat_perl_exec (struct t_plugin_script *script, function); #endif + dSP; ENTER; SAVETMPS; - count = weechat_perl_exec_pv (func, format, argv); + PUSHMARK(SP); + if (format && format[0]) + { + argc = strlen (format); + for (i = 0; i < argc; i++) + { + switch (format[i]) + { + case 's': /* string */ + XPUSHs(sv_2mortal(newSVpv((char *)argv[i], 0))); + break; + case 'i': /* integer */ + XPUSHs(sv_2mortal(newSViv(*((int *)argv[i])))); + break; + case 'h': /* hash */ + hash = weechat_perl_hashtable_to_hash (argv[i]); + XPUSHs(sv_2mortal((SV *)hash)); + break; + } + } + } + PUTBACK; + count = perl_call_pv (func, G_EVAL | G_SCALAR); ret_value = NULL; mem_err = 1; @@ -346,7 +330,8 @@ weechat_perl_exec (struct t_plugin_script *script, } } } - + + PUTBACK; FREETMPS; LEAVE; |