Module: sip-router Branch: 4.0 Commit: c50d559b4da94238a430c059dd02d74e63dd96fe URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c50d559b...
Author: Federico Cabiddu fcabiddu@orange-vallee.net Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Mon Jul 29 07:59:34 2013 +0200
db_flatstore: fixup for new_flat_id function
- locally copy table's name
(cherry picked from commit 8fb0f711aaa611eac8b2776c7e5ae3c5e19243ac)
---
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); }