Module: sip-router
Branch: janakj/flatstore
Commit: 04f0bfe2b359afaad6f227e41ad1e919debff73e
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=04f0bfe…
Author: Bogdan-Andrei Iancu <bogdan(a)voice-system.ro>
Committer: Bogdan-Andrei Iancu <bogdan(a)voice-system.ro>
Date: Fri Apr 18 09:04:44 2008 +0000
- fixed bug in keeping the dir path for the flatstore files - as the path is a substring
of the DB URL, we need to explicitly allocate a str structure for it; otherwise we will
randomly write in memory :D
git-svn-id:
https://openser.svn.sourceforge.net/svnroot/openser/trunk@4040
689a6050-402a-0410-94f2-e92a70836424
---
modules/db_flatstore/km_flatstore.c | 24 +++++++++++++++---------
1 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/modules/db_flatstore/km_flatstore.c b/modules/db_flatstore/km_flatstore.c
index 714ac3b..89cff26 100644
--- a/modules/db_flatstore/km_flatstore.c
+++ b/modules/db_flatstore/km_flatstore.c
@@ -57,6 +57,7 @@ static int parse_flat_url(const str* url, str* path)
db_con_t* flat_db_init(const str* url)
{
db_con_t* res;
+ str* path;
if (!url || !url->s) {
LM_ERR("invalid parameter value\n");
@@ -68,17 +69,22 @@ db_con_t* flat_db_init(const str* url)
* parameter in the table variable, flat_use_table will then pick that
* value and open the file
*/
- res = pkg_malloc(sizeof(db_con_t) + sizeof(struct flat_con*));
+ /* as the table (path) is a substring of the received str, we need to
+ * allocate a separate str struct for it -bogdan
+ */
+ res = pkg_malloc(sizeof(db_con_t)+sizeof(struct flat_con*)+sizeof(str));
if (!res) {
LM_ERR("no pkg memory left\n");
return 0;
}
- memset(res, 0, sizeof(db_con_t) + sizeof(struct flat_con*));
+ memset(res, 0, sizeof(db_con_t) + sizeof(struct flat_con*) + sizeof(str));
+ path = (str*)(((char*)res) + sizeof(db_con_t) + sizeof(struct flat_con*));
- if (parse_flat_url(url, (str*)res->table) < 0) {
+ if (parse_flat_url(url, path) < 0) {
pkg_free(res);
return 0;
}
+ res->table = path;
return res;
}
@@ -99,16 +105,16 @@ int flat_use_table(db_con_t* h, const str* t)
if (CON_TABLE(h)->s != t->s) {
if (CON_TAIL(h)) {
- /* Decrement the reference count
- * of the connection but do not remove
- * it from the connection pool
- */
+ /* Decrement the reference count
+ * of the connection but do not remove
+ * it from the connection pool
+ */
con = (struct flat_con*)CON_TAIL(h);
con->ref--;
-
}
- CON_TAIL(h) = (unsigned long)flat_get_connection((char*)CON_TABLE(h)->s,
(char*)t->s);
+ CON_TAIL(h) = (unsigned long)
+ flat_get_connection((char*)CON_TABLE(h)->s, (char*)t->s);
if (!CON_TAIL(h)) {
return -1;
}