Browse Source

db_postgres: use generic PKG_MEM_ERROR helper defines, fix missing error log

Henning Westerholt 6 years ago
parent
commit
b79423f9ef

+ 18 - 8
src/modules/db_postgres/km_dbase.c

@@ -93,7 +93,7 @@ int pg_alloc_buffer(void)
 	LM_DBG("About to allocate postgres_sql_buf size = %d\n", sql_buffer_size);
 	LM_DBG("About to allocate postgres_sql_buf size = %d\n", sql_buffer_size);
 	postgres_sql_buf = pkg_malloc(sql_buffer_size);
 	postgres_sql_buf = pkg_malloc(sql_buffer_size);
 	if(postgres_sql_buf == NULL) {
 	if(postgres_sql_buf == NULL) {
-		LM_ERR("failed to allocate postgres_sql_buf\n");
+		PKG_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 	return 1;
 	return 1;
@@ -186,8 +186,7 @@ static int db_postgres_submit_query(const db1_con_t *_con, const str *_s)
 
 
 	s = pkg_malloc((_s->len + 1) * sizeof(char));
 	s = pkg_malloc((_s->len + 1) * sizeof(char));
 	if(s == NULL) {
 	if(s == NULL) {
-		LM_ERR("%p db_postgres_submit_query Out of Memory: Query: %.*s\n", _con,
-				_s->len, _s->s);
+		PKG_MEM_ERROR_FMT("connection: %p, query: %.*s\n", _con, _s->len, _s->s);
 		return -1;
 		return -1;
 	}
 	}
 
 
@@ -690,26 +689,37 @@ static pg_constraint_t *db_postgres_constraint_new(
 
 
 	c = pkg_malloc(sizeof(pg_constraint_t));
 	c = pkg_malloc(sizeof(pg_constraint_t));
 
 
-	if(!c)
+	if(!c) {
+		PKG_MEM_ERROR;
 		return NULL;
 		return NULL;
+	}
 	memset(c, 0, sizeof(pg_constraint_t));
 	memset(c, 0, sizeof(pg_constraint_t));
 
 
 	c->database.len = strlen(db);
 	c->database.len = strlen(db);
 	c->database.s = pkg_malloc(c->database.len + 1);
 	c->database.s = pkg_malloc(c->database.len + 1);
-	if(!c->database.s)
+
+	if(!c->database.s) {
+		PKG_MEM_ERROR;
 		goto error;
 		goto error;
+	}
 	strcpy(c->database.s, db);
 	strcpy(c->database.s, db);
 
 
 	c->table.len = table->len;
 	c->table.len = table->len;
 	c->table.s = pkg_malloc(c->table.len + 1);
 	c->table.s = pkg_malloc(c->table.len + 1);
-	if(!c->table.s)
+
+	if(!c->table.s) {
+		PKG_MEM_ERROR;
 		goto error;
 		goto error;
+	}
 	strcpy(c->table.s, table->s);
 	strcpy(c->table.s, table->s);
 
 
 	c->unique.len = strlen(unique);
 	c->unique.len = strlen(unique);
 	c->unique.s = pkg_malloc(c->unique.len + 1);
 	c->unique.s = pkg_malloc(c->unique.len + 1);
-	if(!c->unique.s)
+
+	if(!c->unique.s) {
+		PKG_MEM_ERROR;
 		goto error;
 		goto error;
+	}
 	strcpy(c->unique.s, unique);
 	strcpy(c->unique.s, unique);
 
 
 	db_postgres_constraint_add(c);
 	db_postgres_constraint_add(c);
@@ -975,7 +985,7 @@ int db_postgres_start_transaction(db1_con_t *_h, db_locking_t _l)
 												+ lock_end_str->len)
 												+ lock_end_str->len)
 										* sizeof(char)))
 										* sizeof(char)))
 					== NULL) {
 					== NULL) {
-				LM_ERR("allocating pkg memory\n");
+				PKG_MEM_ERROR;
 				goto error;
 				goto error;
 			}
 			}
 
 

+ 1 - 3
src/modules/db_postgres/km_pg_con.c

@@ -65,9 +65,7 @@ struct pg_con *db_postgres_new_connection(struct db_id *id)
 
 
 	ptr = (struct pg_con *)pkg_malloc(sizeof(struct pg_con));
 	ptr = (struct pg_con *)pkg_malloc(sizeof(struct pg_con));
 	if(!ptr) {
 	if(!ptr) {
-		LM_ERR("failed trying to allocated %lu bytes for connection structure."
-			   "\n",
-				(unsigned long)sizeof(struct pg_con));
+		PKG_MEM_ERROR_FMT("%lu bytes for connection structure", (unsigned long)sizeof(struct pg_con));
 		return 0;
 		return 0;
 	}
 	}
 	LM_DBG("%p=pkg_malloc(%lu)\n", ptr, (unsigned long)sizeof(struct pg_con));
 	LM_DBG("%p=pkg_malloc(%lu)\n", ptr, (unsigned long)sizeof(struct pg_con));

+ 2 - 2
src/modules/db_postgres/km_res.c

@@ -105,7 +105,7 @@ int db_postgres_get_columns(const db1_con_t *_h, db1_res_t *_r)
 
 
 		RES_NAMES(_r)[col] = (str *)pkg_malloc(sizeof(str));
 		RES_NAMES(_r)[col] = (str *)pkg_malloc(sizeof(str));
 		if(!RES_NAMES(_r)[col]) {
 		if(!RES_NAMES(_r)[col]) {
-			LM_ERR("no private memory left\n");
+			PKG_MEM_ERROR;
 			db_free_columns(_r);
 			db_free_columns(_r);
 			return -4;
 			return -4;
 		}
 		}
@@ -205,7 +205,7 @@ int db_postgres_convert_rows(const db1_con_t *_h, db1_res_t *_r)
 	len = sizeof(char *) * RES_COL_N(_r);
 	len = sizeof(char *) * RES_COL_N(_r);
 	row_buf = (char **)pkg_malloc(len);
 	row_buf = (char **)pkg_malloc(len);
 	if(!row_buf) {
 	if(!row_buf) {
-		LM_ERR("no private memory left\n");
+		PKG_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 	LM_DBG("allocate for %d columns %d bytes in row buffer at %p\n",
 	LM_DBG("allocate for %d columns %d bytes in row buffer at %p\n",

+ 1 - 1
src/modules/db_postgres/km_val.c

@@ -69,7 +69,7 @@ int db_postgres_str2val(
 		}
 		}
 		VAL_BLOB(_v).s = pkg_malloc(VAL_BLOB(_v).len + 1);
 		VAL_BLOB(_v).s = pkg_malloc(VAL_BLOB(_v).len + 1);
 		if(VAL_BLOB(_v).s == NULL) {
 		if(VAL_BLOB(_v).s == NULL) {
-			LM_ERR("no private memory left\n");
+			PKG_MEM_ERROR;
 			PQfreemem(tmp_s);
 			PQfreemem(tmp_s);
 			return -8;
 			return -8;
 		}
 		}

+ 5 - 5
src/modules/db_postgres/pg_cmd.c

@@ -94,7 +94,7 @@ static int gen_cmd_name(db_cmd_t *cmd)
 
 
 	pcmd->name = pkg_malloc(len + 1);
 	pcmd->name = pkg_malloc(len + 1);
 	if(pcmd->name == NULL) {
 	if(pcmd->name == NULL) {
-		ERR("postgres: No memory left\n");
+		PKG_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 	memcpy(pcmd->name, c, len);
 	memcpy(pcmd->name, c, len);
@@ -129,7 +129,7 @@ static int create_pg_params(db_cmd_t *cmd)
 	pcmd->params.fmt = (int *)pkg_malloc(sizeof(int) * num);
 	pcmd->params.fmt = (int *)pkg_malloc(sizeof(int) * num);
 
 
 	if(!pcmd->params.val || !pcmd->params.len || !pcmd->params.fmt) {
 	if(!pcmd->params.val || !pcmd->params.len || !pcmd->params.fmt) {
-		ERR("postgres: No memory left\n");
+	        PKG_MEM_ERROR;
 		goto error;
 		goto error;
 	}
 	}
 
 
@@ -231,7 +231,7 @@ static int get_types(db_cmd_t *cmd)
 			f = DB_GET_PAYLOAD(cmd->result + i);
 			f = DB_GET_PAYLOAD(cmd->result + i);
 			f->name = pkg_malloc(strlen(PQfname(pcmd->types, i)) + 1);
 			f->name = pkg_malloc(strlen(PQfname(pcmd->types, i)) + 1);
 			if(f->name == NULL) {
 			if(f->name == NULL) {
-				ERR("postgres: Out of private memory\n");
+			        PKG_MEM_ERROR;
 				goto error;
 				goto error;
 			}
 			}
 			strcpy(f->name, PQfname(pcmd->types, i));
 			strcpy(f->name, PQfname(pcmd->types, i));
@@ -298,7 +298,7 @@ int pg_cmd(db_cmd_t *cmd)
 
 
 	pcmd = (struct pg_cmd *)pkg_malloc(sizeof(struct pg_cmd));
 	pcmd = (struct pg_cmd *)pkg_malloc(sizeof(struct pg_cmd));
 	if(pcmd == NULL) {
 	if(pcmd == NULL) {
-		ERR("postgres: No memory left\n");
+	        PKG_MEM_ERROR;
 		goto error;
 		goto error;
 	}
 	}
 	memset(pcmd, '\0', sizeof(struct pg_cmd));
 	memset(pcmd, '\0', sizeof(struct pg_cmd));
@@ -329,7 +329,7 @@ int pg_cmd(db_cmd_t *cmd)
 		case DB_SQL:
 		case DB_SQL:
 			pcmd->sql_cmd.s = (char *)pkg_malloc(cmd->table.len + 1);
 			pcmd->sql_cmd.s = (char *)pkg_malloc(cmd->table.len + 1);
 			if(pcmd->sql_cmd.s == NULL) {
 			if(pcmd->sql_cmd.s == NULL) {
-				ERR("postgres: Out of private memory\n");
+			        PKG_MEM_ERROR;
 				goto error;
 				goto error;
 			}
 			}
 			memcpy(pcmd->sql_cmd.s, cmd->table.s, cmd->table.len);
 			memcpy(pcmd->sql_cmd.s, cmd->table.s, cmd->table.len);

+ 1 - 1
src/modules/db_postgres/pg_con.c

@@ -205,7 +205,7 @@ int pg_con(db_con_t *con)
 
 
 	pcon = (struct pg_con *)pkg_malloc(sizeof(struct pg_con));
 	pcon = (struct pg_con *)pkg_malloc(sizeof(struct pg_con));
 	if(!pcon) {
 	if(!pcon) {
-		LOG(L_ERR, "postgres: No memory left\n");
+		PKG_MEM_ERROR;
 		goto error;
 		goto error;
 	}
 	}
 	memset(pcon, '\0', sizeof(struct pg_con));
 	memset(pcon, '\0', sizeof(struct pg_con));

+ 1 - 1
src/modules/db_postgres/pg_fld.c

@@ -70,7 +70,7 @@ int pg_fld(db_fld_t *fld, char *table)
 
 
 	res = (struct pg_fld *)pkg_malloc(sizeof(struct pg_fld));
 	res = (struct pg_fld *)pkg_malloc(sizeof(struct pg_fld));
 	if(res == NULL) {
 	if(res == NULL) {
-		ERR("postgres: No memory left\n");
+		PKG_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 	memset(res, '\0', sizeof(struct pg_fld));
 	memset(res, '\0', sizeof(struct pg_fld));

+ 1 - 1
src/modules/db_postgres/pg_res.c

@@ -53,7 +53,7 @@ int pg_res(db_res_t *res)
 
 
 	pres = (struct pg_res *)pkg_malloc(sizeof(struct pg_res));
 	pres = (struct pg_res *)pkg_malloc(sizeof(struct pg_res));
 	if(pres == NULL) {
 	if(pres == NULL) {
-		ERR("postgres: No memory left\n");
+		PKG_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 	if(db_drv_init(&pres->gen, pg_res_free) < 0)
 	if(db_drv_init(&pres->gen, pg_res_free) < 0)

+ 1 - 1
src/modules/db_postgres/pg_sql.c

@@ -118,7 +118,7 @@ static inline int sb_add(struct string_buffer *sb, str *nstr)
 							 * sb->increment;
 							 * sb->increment;
 		newp = pkg_malloc(new_size);
 		newp = pkg_malloc(new_size);
 		if(!newp) {
 		if(!newp) {
-			ERR("postgres: No memory left\n");
+			PKG_MEM_ERROR;
 			return -1;
 			return -1;
 		}
 		}
 		if(sb->s) {
 		if(sb->s) {

+ 2 - 1
src/modules/db_postgres/pg_uri.c

@@ -83,6 +83,7 @@ static int dupl_string(char **dst, const char *begin, const char *end)
 
 
 	*dst = pkg_malloc(end - begin + 1);
 	*dst = pkg_malloc(end - begin + 1);
 	if((*dst) == NULL) {
 	if((*dst) == NULL) {
+		PKG_MEM_ERROR;
 		return -1;
 		return -1;
 	}
 	}
 
 
@@ -304,7 +305,7 @@ int pg_uri(db_uri_t *uri)
 
 
 	puri = (struct pg_uri *)pkg_malloc(sizeof(struct pg_uri));
 	puri = (struct pg_uri *)pkg_malloc(sizeof(struct pg_uri));
 	if(puri == NULL) {
 	if(puri == NULL) {
-		ERR("postgres: No memory left\n");
+		PKG_MEM_ERROR;
 		goto error;
 		goto error;
 	}
 	}
 	memset(puri, '\0', sizeof(struct pg_uri));
 	memset(puri, '\0', sizeof(struct pg_uri));