perl plugin: Do not abort while preparing the stack for a subroutine call.
[collectd.git] / src / perl.c
index 346f960..7558a50 100644 (file)
@@ -700,11 +700,19 @@ static int pplugin_call_all (pTHX_ int type, ...)
                ds = va_arg (ap, data_set_t *);
                vl = va_arg (ap, value_list_t *);
 
-               if (-1 == data_set2av (aTHX_ ds, pds))
-                       return -1;
+               if (-1 == data_set2av (aTHX_ ds, pds)) {
+                       av_clear (pds);
+                       av_undef (pds);
+                       pds = Nullav;
+                       ret = -1;
+               }
 
-               if (-1 == value_list2hv (aTHX_ vl, ds, pvl))
-                       return -1;
+               if (-1 == value_list2hv (aTHX_ vl, ds, pvl)) {
+                       hv_clear (pvl);
+                       hv_undef (pvl);
+                       pvl = Nullhv;
+                       ret = -1;
+               }
 
                XPUSHs (sv_2mortal (newSVpv (ds->type, 0)));
                XPUSHs (sv_2mortal (newRV_noinc ((SV *)pds)));
@@ -738,8 +746,12 @@ static int pplugin_call_all (pTHX_ int type, ...)
 
                n = va_arg (ap, notification_t *);
 
-               if (-1 == notification2hv (aTHX_ n, notif))
-                       return -1;
+               if (-1 == notification2hv (aTHX_ n, notif)) {
+                       hv_clear (notif);
+                       hv_undef (notif);
+                       notif = Nullhv;
+                       ret = -1;
+               }
 
                XPUSHs (sv_2mortal (newRV_noinc ((SV *)notif)));
        }
@@ -827,7 +839,7 @@ static XS (Collectd_plugin_unregister_ds)
        log_debug ("Collectd::plugin_unregister_data_set: type = \"%s\"",
                        SvPV_nolen (ST (0)));
 
-       if (0 == pplugin_unregister_data_set (SvPV_nolen (ST (1))))
+       if (0 == pplugin_unregister_data_set (SvPV_nolen (ST (0))))
                XSRETURN_YES;
        else
                XSRETURN_EMPTY;
@@ -1210,6 +1222,7 @@ static int perl_shutdown (void)
                        aTHX, perl_threads->number_of_threads);
 
        plugin_unregister_log ("perl");
+       plugin_unregister_notification ("perl");
        plugin_unregister_init ("perl");
        plugin_unregister_read ("perl");
        plugin_unregister_write ("perl");