Module: sip-router
Branch: master
Commit: b4af74a164d521f7db21abb9257e33e6e82dc985
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b4af74a164d521f7db21abb9257e33e6e82dc985

Author: Alex Hermann <[email protected]>
Committer: Alex Hermann <[email protected]>
Date:   Mon Sep  5 16:41:55 2011 +0200

lib/srdb1: Fix memory leak with string memory in db_val2pv_spec()

---

 lib/srdb1/db_ut.c |    7 ++++++-
 lib/srdb1/db_ut.h |    5 ++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/srdb1/db_ut.c b/lib/srdb1/db_ut.c
index 0331896..babe0e7 100644
--- a/lib/srdb1/db_ut.c
+++ b/lib/srdb1/db_ut.c
@@ -491,10 +491,15 @@ int db_val2pv_spec(struct sip_msg* msg, db_val_t *dbval, 
pv_spec_t *pvs)
        if (pv_set_spec_value(msg, pvs, 0, &pv) != 0)
        {
                LM_ERR("Failed to add value to spec\n");
-               if (pv.flags == PV_VAL_STR)
+               if (pv.flags == PV_VAL_STR && pv.rs.len > 0)
                        pkg_free(pv.rs.s);
                return -1;
        }
 
+       /* free string memory */
+       if (pv.flags == PV_VAL_STR && pv.rs.len > 0) {
+               pkg_free(pv.rs.s);
+       }
+
        return 0;
 }
diff --git a/lib/srdb1/db_ut.h b/lib/srdb1/db_ut.h
index 9440467..790780f 100644
--- a/lib/srdb1/db_ut.h
+++ b/lib/srdb1/db_ut.h
@@ -208,7 +208,10 @@ int db_print_set(const db1_con_t* _c, char* _b, const int 
_l,
 
 
 /**
- * Convert db_val to pv_spec_t
+ * Convert db_val_t to pv_spec_t
+ *
+ * On success, when the PV type is string and longer than 0 chars,
+ * the string must be freed by the caller after use.
  * 
  * \param msg sip msg structure
  * \param dbval database value


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to