Module: sip-router Branch: master Commit: 2e56720769913c55cacc83fe3a31f44f072e7590 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2e567207...
Author: Henning Westerholt henning.westerholt@1und1.de Committer: Henning Westerholt henning.westerholt@1und1.de Date: Tue Jun 29 18:11:58 2010 +0200
db_postgres(old API) FS#77: fix BLOBs with postgres
fix BLOBs with postgres, also add a null-termination as the other SQL databases in order to be able to work with the presence modules
---
modules/db_postgres/km_val.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/modules/db_postgres/km_val.c b/modules/db_postgres/km_val.c index cb3fe9f..9faa5b5 100644 --- a/modules/db_postgres/km_val.c +++ b/modules/db_postgres/km_val.c @@ -72,16 +72,18 @@ int db_postgres_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const LM_ERR("PQunescapeBytea failed\n"); return -7; } - VAL_BLOB(_v).s = pkg_malloc(VAL_BLOB(_v).len); + VAL_BLOB(_v).s = pkg_malloc(VAL_BLOB(_v).len + 1); if (VAL_BLOB(_v).s == NULL) { LM_ERR("no private memory left\n"); PQfreemem(tmp_s); return -8; } - LM_DBG("allocate %d bytes memory for BLOB at %p", VAL_BLOB(_v).len, VAL_BLOB(_v).s); + LM_DBG("allocate %d bytes memory for BLOB at %p", VAL_BLOB(_v).len + 1, VAL_BLOB(_v).s); memcpy(VAL_BLOB(_v).s, tmp_s, VAL_BLOB(_v).len); PQfreemem(tmp_s);
+ VAL_BLOB(_v).s[VAL_BLOB(_v).len] = '\0'; + VAL_BLOB(_v).len++; VAL_TYPE(_v) = DB1_BLOB; VAL_FREE(_v) = 1;