<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div><span>Hi Henning,</span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;"><span><br></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;"><span><br></span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;"><span>Thank you! This is good news.</span></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;"><span>I can confirm that the crash during the shutdown is fixed!</span></div><div>We are running now with the new module, I'll keep an eye on
 it.</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;">Regards,</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;">Dragos</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: arial, helvetica, sans-serif; background-color: transparent; font-style: normal;"><br></div>  <div style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"> <div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt;"> <div dir="ltr"> <hr size="1">  <font size="2" face="Arial"> <b><span style="font-weight:bold;">From:</span></b> Henning Westerholt <hw@kamailio.org><br> <b><span
 style="font-weight: bold;">To:</span></b> sr-dev@lists.sip-router.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Sunday, June 30, 2013 3:46 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> [sr-dev] git:master: memcached: fix crash during shutdown,
 make used memory manager configurable<br> </font> </div> <div class="y_msg_container"><br>Module: sip-router<br>Branch: master<br>Commit: df41d7f4e0cd8bd0c328f94360a6b3a3f3e9d59b<br>URL:    <a href="http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=df41d7f4e0cd8bd0c328f94360a6b3a3f3e9d59b" target="_blank">http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=df41d7f4e0cd8bd0c328f94360a6b3a3f3e9d59b</a><br><br>Author: Henning Westerholt <<a ymailto="mailto:hw@kamailio.org" href="mailto:hw@kamailio.org">hw@kamailio.org</a>><br>Committer: Henning Westerholt <<a ymailto="mailto:hw@kamailio.org" href="mailto:hw@kamailio.org">hw@kamailio.org</a>><br>Date:   Sun Jun 30 15:42:17 2013 +0200<br><br>memcached: fix crash during shutdown, make used memory manager configurable<br><br>* fix a crash during shutwdown, as reported from Dragos Oancea, droancea at yahoo dot com<br>* make memcache client library
 memory manager configurable, as default use<br>  the one from the system as this is probably the most tested configuration<br>  in the field<br>* the internal memory manager should provide a better performance in this case,<br>  but as the old library has some issues with the internal one, we better stay<br>  with this<br>* documentation will be provided in the next commit<br><br>---<br><br> modules/memcached/memcached.c |   45 ++++++++++++++++++++---------------------<br> modules/memcached/memcached.h |    4 ++-<br> test/unit/45.cfg              |    1 +<br> 3 files changed, 26 insertions(+), 24 deletions(-)<br><br>diff --git a/modules/memcached/memcached.c b/modules/memcached/memcached.c<br>index 32852d9..86a08b3 100644<br>--- a/modules/memcached/memcached.c<br>+++ b/modules/memcached/memcached.c<br>@@ -43,7 +43,9 @@ unsigned int mcd_expire = 0;<br> /*! cache storage mode,
 set or add */<br> unsigned int mcd_mode = 0;<br> /*! server timeout in ms*/<br>-int mcd_timeout = 5000;<br>+unsigned int mcd_timeout = 5000;<br>+/*! Internal or system memory manager, default is system */<br>+unsigned int mcd_memory = 0;<br> /*! memcached handle */<br> struct memcached_st *memcached_h;<br> /*! memcached server list */<br>@@ -76,9 +78,10 @@ static pv_export_t mod_pvs[] = {<br>  */<br> static param_export_t params[] = {<br>     {"servers", STR_PARAM, &mcd_srv_str },<br>-    {"expire",   INT_PARAM, &mcd_expire },<br>+    {"expire",  INT_PARAM, &mcd_expire },<br>     {"timeout", INT_PARAM, &mcd_timeout },<br>     {"mode",    INT_PARAM, &mcd_mode },<br>+    {"memory",  INT_PARAM, &mcd_memory },<br>     {0, 0, 0}<br> };<br> <br>@@ -105,10 +108,12 @@ struct module_exports exports = {<br>
 /*!<br>  * \brief Wrapper functions around our internal memory management<br>  * \param mem freed memory<br>+ * \note pkg_free does not allow NULL pointer as standard free, therefore we check it here<br>  * \see pkg_free<br>  */<br> static inline void mcd_free(memcached_st *ptr, void *mem, void *context) {<br>-    pkg_free(mem);<br>+        if (mem)<br>+            pkg_free(mem);<br> }<br> <br> <br>@@ -201,17 +206,21 @@ static int mod_init(void) {<br>     }<br>     LM_DBG("allocated new server handle at %p", memcached_h);<br> <br>-    LM_DBG("set memory manager callbacks");<br>-    rc = memcached_set_memory_allocators(memcached_h, (memcached_malloc_fn)mcd_malloc,<br>+    if (mcd_memory == 1) {<br>+        LM_INFO("Use internal kamailio memory manager for
 memcached client library");<br>+        rc = memcached_set_memory_allocators(memcached_h, (memcached_malloc_fn)mcd_malloc,<br>                          (memcached_free_fn)mcd_free, (memcached_realloc_fn)mcd_realloc,<br>                          (memcached_calloc_fn)mcd_calloc, NULL);<br>-    if (rc == MEMCACHED_SUCCESS) {<br>-        LM_DBG("memory manager callbacks set");<br>+        if (rc == MEMCACHED_SUCCESS) {<br>+            LM_DBG("memory manager callbacks set");<br>+        } else {<br>+            LM_ERR("memory manager callbacks not set, returned %s.\n",
 memcached_strerror(memcached_h, rc));<br>+            return -1;<br>+        }<br>     } else {<br>-        LM_ERR("memory manager callbacks not set, returned %s.\n", memcached_strerror(memcached_h, rc));<br>-        return -1;<br>+        LM_INFO("Use system memory manager for memcached client library");<br>     }<br>-    <br>+<br>         servers = memcached_server_list_append(servers, server, atoi(port), &rc);<br>     <br>     if (memcached_behavior_set(memcached_h, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, mcd_timeout) != MEMCACHED_SUCCESS) {<br>@@ -241,20 +250,10 @@ static int mod_init(void) {<br>  * \brief Module shutdown function<br>  */<br> static void mod_destroy(void)
 {<br>-    memcached_return rc;<br>-    <br>     if (servers != NULL)<br>         memcached_server_list_free(servers);<br>     <br>-    /* unset custom memory manager to enable clean shutdown of in system memory allocated server structure */<br>-    LM_DBG("remove memory manager callbacks");<br>-    rc = memcached_set_memory_allocators(memcached_h, NULL, NULL, NULL, NULL, NULL);<br>-    if (rc == MEMCACHED_SUCCESS) {<br>-        LM_DBG("memory manager callbacks removed");<br>-    } else {<br>-        LM_ERR("memory manager callbacks not removed, returned %s but continue anyway.\n", memcached_strerror(memcached_h, rc));<br>-    }<br>-    <br>-    if (memcached_h !=
 NULL)<br>-        memcached_free(memcached_h);<br>+    /* Crash on shutdown with internal memory manager, even if we disable the mm callbacks */<br>+    if (mcd_memory != 1 && memcached_h != NULL)<br>+                memcached_free(memcached_h);<br> }<br>diff --git a/modules/memcached/memcached.h b/modules/memcached/memcached.h<br>index 4d9a875..407d39f 100644<br>--- a/modules/memcached/memcached.h<br>+++ b/modules/memcached/memcached.h<br>@@ -35,7 +35,9 @@ extern unsigned int mcd_expire;<br> /*! cache storage mode, set or add */<br> extern unsigned int mcd_mode;<br> /*! server timeout */<br>-extern int mcd_timeout;<br>+extern unsigned int mcd_timeout;<br>+/*! Internal or system memory manager */<br>+extern unsigned int mcd_memory;<br> /*! memcached handle */<br> extern struct memcached_st* memcached_h;<br> /*! memcached server list
 */<br>diff --git a/test/unit/45.cfg b/test/unit/45.cfg<br>index f2b8c93..a170672 100644<br>--- a/test/unit/45.cfg<br>+++ b/test/unit/45.cfg<br>@@ -29,6 +29,7 @@ loadmodule "xlog/xlog.so"<br> modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")<br> modparam("usrloc", "db_mode", 3)<br> modparam("usrloc", "db_url", "mysql://kamailio:<a ymailto="mailto:kamailiorw@localhost" href="mailto:kamailiorw@localhost">kamailiorw@localhost</a>/kamailio")<br>+modparam("memcached", "memory", 0)<br> <br> #-----------------------Routing configuration---------------------------------#<br> route{<br><br><br>_______________________________________________<br>sr-dev mailing list<br><a ymailto="mailto:sr-dev@lists.sip-router.org" href="mailto:sr-dev@lists.sip-router.org">sr-dev@lists.sip-router.org</a><br><a href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev</a><br><br><br></div>
 </div> </div>  </div></body></html>