Module: sip-router
Branch: master
Commit: 8fb0f711aaa611eac8b2776c7e5ae3c5e19243ac
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8fb0f71…
Author: Federico Cabiddu <fcabiddu(a)orange-vallee.net>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Jul 29 07:59:34 2013 +0200
db_flatstore: fixup for new_flat_id function
- locally copy table's name
---
modules/db_flatstore/km_flat_id.c | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/modules/db_flatstore/km_flat_id.c b/modules/db_flatstore/km_flat_id.c
index 3294528..11f9fbe 100644
--- a/modules/db_flatstore/km_flat_id.c
+++ b/modules/db_flatstore/km_flat_id.c
@@ -35,6 +35,8 @@
struct flat_id* new_flat_id(char* dir, char* table)
{
struct flat_id* ptr;
+ char* t;
+ int t_len;
if (!dir || !table) {
LM_ERR("invalid parameter(s)\n");
@@ -48,10 +50,20 @@ struct flat_id* new_flat_id(char* dir, char* table)
}
memset(ptr, 0, sizeof(struct flat_id));
+ /* alloc memory for the table name */
+ t_len = strlen(table);
+ t = (char*)pkg_malloc(t_len);
+ if (!t) {
+ LM_ERR("no pkg memory left\n");
+ return 0;
+ }
+ memset(t, 0, t_len);
+
ptr->dir.s = dir;
ptr->dir.len = strlen(dir);
- ptr->table.s = table;
- ptr->table.len = strlen(table);
+ memcpy(t, table, t_len);
+ ptr->table.s = t;
+ ptr->table.len = t_len;
return ptr;
}
@@ -78,5 +90,7 @@ unsigned char cmp_flat_id(struct flat_id* id1, struct flat_id* id2)
void free_flat_id(struct flat_id* id)
{
if (!id) return;
+ if (id->table.s)
+ pkg_free(id->table.s);
pkg_free(id);
}