2
0
Эх сурвалжийг харах

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
Henning Westerholt 15 жил өмнө
parent
commit
2e56720769

+ 4 - 2
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;