]> source.dussan.org Git - rspamd.git/commitdiff
* Use internal task pool for memcached operation exported for perl
authorcebka@mailsupport.rambler.ru <cebka@mailsupport.rambler.ru>
Sun, 21 Sep 2008 03:23:29 +0000 (07:23 +0400)
committercebka@mailsupport.rambler.ru <cebka@mailsupport.rambler.ru>
Sun, 21 Sep 2008 03:23:29 +0000 (07:23 +0400)
* Make AV reference mortal as it is described in perlxs (3)

perl.c
perl/rspamd.xs

diff --git a/perl.c b/perl.c
index 2e1c9e5d7a1b172c97bc9fbc38cb9cf114990316..8702838351a8c2e72e8af389b484445103f442a5 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -141,7 +141,7 @@ perl_call_chain_filter (const char *function, struct worker_task *task, int *mar
        }
        PUSHMARK (SP);
        XPUSHs (sv_2mortal (newSViv (PTR2IV (task))));
-       XPUSHs (AvARRAY (av));
+       XPUSHs (sv_2mortal ((SV *)AvARRAY (av)));
        PUTBACK;
        
        call_pv (function, G_SCALAR);
@@ -179,8 +179,6 @@ void perl_call_memcached_callback (memcached_ctx_t *ctx, memc_error_t error, voi
 
        call_sv (callback_data->callback, G_SCALAR);
        
-       free (callback_data);
-       free (ctx);
     /* Set save point */
     callback_data->task->save.saved = 0;
        process_filters (callback_data->task);
index 1632ebadefda216a17b4bb216389fae97cc6aed8..6bbaaddf1feaad02218686c08c8b0d45d4996547 100644 (file)
@@ -13,6 +13,7 @@
 #include "../config.h"
 #include "../main.h"
 #include "../perl.h"
+#include "../mem_pool.h"
 
 #define perl_set_session(r)                                                                                                    \
        r = INT2PTR(struct worker_task *, SvIV((SV *) SvRV(ST(0))))
@@ -136,14 +137,14 @@ read_memcached_key (r, key, datalen, callback)
     callback = SvRV(ST(3));
 
     /* Copy old ctx to new one */
-    ctx = malloc (sizeof (memcached_ctx_t));
+    ctx = memory_pool_alloc (r->task_pool, sizeof (memcached_ctx_t));
     if (ctx == NULL) {
         XSRETURN_UNDEF;
     }
     memcpy (ctx, r->memc_ctx, sizeof (memcached_ctx_t));
     /* Set perl callback */
     ctx->callback = perl_call_memcached_callback;
-    callback_data = malloc (sizeof (struct _param));
+    callback_data = memory_pool_alloc (r->task_pool, sizeof (struct _param));
     if (callback_data == NULL) {
                XSRETURN_UNDEF;
     }
@@ -152,7 +153,7 @@ read_memcached_key (r, key, datalen, callback)
     ctx->callback_data = (void *)callback_data;
 
     strlcpy (param.key, key, sizeof (param.key));
-    param.buf = malloc (datalen);
+       param.buf = memory_pool_alloc (r->task_pool, datalen);
     if (param.buf != NULL) {
         param.bufsize = datalen;
     }
@@ -186,14 +187,14 @@ write_memcached_key (r, key, data, expire, callback)
     callback = SvRV(ST(4));
 
     /* Copy old ctx to new one */
-    ctx = malloc (sizeof (memcached_ctx_t));
+    ctx = memory_pool_alloc (r->task_pool, sizeof (memcached_ctx_t));
     if (ctx == NULL) {
         XSRETURN_UNDEF;
     }
     memcpy (ctx, r->memc_ctx, sizeof (memcached_ctx_t));
     /* Set perl callback */
     ctx->callback = perl_call_memcached_callback;
-    callback_data = malloc (sizeof (struct _param));
+    callback_data = memory_pool_alloc (r->task_pool, sizeof (struct _param));
     if (callback_data == NULL) {
                XSRETURN_UNDEF;
     }
@@ -231,14 +232,14 @@ delete_memcached_key (r, key, callback)
     callback = SvRV(ST(2));
 
     /* Copy old ctx to new one */
-    ctx = malloc (sizeof (memcached_ctx_t));
+    ctx = memory_pool_alloc (r->task_pool, sizeof (memcached_ctx_t));
     if (ctx == NULL) {
         XSRETURN_UNDEF;
     }
     memcpy (ctx, r->memc_ctx, sizeof (memcached_ctx_t));
     /* Set perl callback */
     ctx->callback = perl_call_memcached_callback;
-    callback_data = malloc (sizeof (struct _param));
+    callback_data = memory_pool_alloc (r->task_pool, sizeof (struct _param));
     if (callback_data == NULL) {
                XSRETURN_UNDEF;
     }