Module: sip-router
Branch: janakj/postgres
Commit: d65be2c006880ec492de2d106c570011efcac0e6
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d65be2c…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Mon Sep 1 10:27:02 2008 +0000
- multiple fixes:
1) test memory allocations
2) return code overlapping in case of error (missing break)
3) bogus/ not needed NULL tests for result freeing
- credits goes to Bogdan
git-svn-id:
https://openser.svn.sourceforge.net/svnroot/openser/trunk@4784
689a6050-402a-0410-94f2-e92a70836424
---
modules/db_postgres/km_dbase.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/modules/db_postgres/km_dbase.c b/modules/db_postgres/km_dbase.c
index 29f817c..49c276c 100644
--- a/modules/db_postgres/km_dbase.c
+++ b/modules/db_postgres/km_dbase.c
@@ -405,6 +405,11 @@ int db_postgres_store_result(const db_con_t* _con, db_res_t** _r)
int rc = 0;
*_r = db_new_result();
+ if (*_r==NULL) {
+ LM_ERR("failed to init new result\n");
+ rc = -1;
+ goto done;
+ }
while (1) {
if ((res = PQgetResult(CON_CONNECTION(_con)))) {
@@ -421,18 +426,20 @@ int db_postgres_store_result(const db_con_t* _con, db_res_t** _r)
switch(pqresult) {
case PGRES_COMMAND_OK:
- /* Successful completion of a command returning no data (such as INSERT or UPDATE). */
+ /* Successful completion of a command returning no data
+ * (such as INSERT or UPDATE). */
rc = 0;
break;
case PGRES_TUPLES_OK:
- /* Successful completion of a command returning data (such as a SELECT or SHOW). */
+ /* Successful completion of a command returning data
+ * (such as a SELECT or SHOW). */
if (db_postgres_convert_result(_con, *_r) < 0) {
LM_ERR("%p Error returned from convert_result()\n", _con);
- if (*_r) db_free_result(*_r);
-
+ db_free_result(*_r);
*_r = 0;
rc = -4;
+ break;
}
rc = 0;
break;
@@ -441,7 +448,7 @@ int db_postgres_store_result(const db_con_t* _con, db_res_t** _r)
LM_ERR("%p - invalid query, execution aborted\n", _con);
LM_ERR("%p: %s\n", _con, PQresStatus(pqresult));
LM_ERR("%p: %s\n", _con, PQresultErrorMessage(CON_RESULT(_con)));
- if (*_r) db_free_result(*_r);
+ db_free_result(*_r);
*_r = 0;
rc = -3;
break;
@@ -458,13 +465,13 @@ int db_postgres_store_result(const db_con_t* _con, db_res_t** _r)
LM_ERR("%p Probable invalid query\n", _con);
LM_ERR("%p: %s\n", _con, PQresStatus(pqresult));
LM_ERR("%p: %s\n", _con, PQresultErrorMessage(CON_RESULT(_con)));
- if (*_r) db_free_result(*_r);
-
+ db_free_result(*_r);
*_r = 0;
rc = -4;
break;
}
+done:
free_query(_con);
return (rc);
}