[sr-dev] git:master:ab627c14: alias_db: simplify error handling for db query function
Daniel-Constantin Mierla
miconda at gmail.com
Thu Jul 20 16:45:19 CEST 2017
Module: kamailio
Branch: master
Commit: ab627c14e6f06b8e568f9b6ab4e3cd396368d6bb
URL: https://github.com/kamailio/kamailio/commit/ab627c14e6f06b8e568f9b6ab4e3cd396368d6bb
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-07-20T16:35:15+02:00
alias_db: simplify error handling for db query function
---
Modified: src/modules/alias_db/alookup.c
---
Diff: https://github.com/kamailio/kamailio/commit/ab627c14e6f06b8e568f9b6ab4e3cd396368d6bb.diff
Patch: https://github.com/kamailio/kamailio/commit/ab627c14e6f06b8e568f9b6ab4e3cd396368d6bb.patch
---
diff --git a/src/modules/alias_db/alookup.c b/src/modules/alias_db/alookup.c
index d980d97113..28dd916999 100644
--- a/src/modules/alias_db/alookup.c
+++ b/src/modules/alias_db/alookup.c
@@ -103,8 +103,8 @@ static int alias_db_query(struct sip_msg* _msg, str table,
adbf.use_table(db_handle, &table);
if(adbf.query( db_handle, db_keys, NULL, db_vals, db_cols,
- (flags&ALIAS_DOMAIN_FLAG)?2:1 /*no keys*/, 2 /*no cols*/,
- NULL, &db_res)!=0)
+ (flags&ALIAS_DOMAIN_FLAG)?2:1 /*no keys*/, 2 /*no cols*/,
+ NULL, &db_res)!=0 || db_res==NULL)
{
LM_ERR("failed to query database\n");
goto err_server;
@@ -113,9 +113,7 @@ static int alias_db_query(struct sip_msg* _msg, str table,
if (RES_ROW_N(db_res)<=0 || RES_ROWS(db_res)[0].values[0].nul != 0)
{
LM_DBG("no alias found for R-URI\n");
- if (db_res!=NULL && adbf.free_result(db_handle, db_res) < 0)
- LM_DBG("failed to freeing result of query\n");
- return -1;
+ goto err_server;
}
memcpy(useruri_buf, "sip:", 4);
@@ -144,10 +142,6 @@ static int alias_db_query(struct sip_msg* _msg, str table,
break;
default:
LM_ERR("unknown type of DB user column\n");
- if (db_res != NULL && adbf.free_result(db_handle, db_res) < 0)
- {
- LM_DBG("failed to freeing result of query\n");
- }
goto err_server;
}
@@ -180,10 +174,6 @@ static int alias_db_query(struct sip_msg* _msg, str table,
break;
default:
LM_ERR("unknown type of DB user column\n");
- if (db_res != NULL && adbf.free_result(db_handle, db_res) < 0)
- {
- LM_DBG("failed to freeing result of query\n");
- }
goto err_server;
}
user_s.s = useruri_buf;
@@ -198,14 +188,18 @@ static int alias_db_query(struct sip_msg* _msg, str table,
/**
* Free the DB result
*/
- if (db_res!=NULL && adbf.free_result(db_handle, db_res) < 0)
+ if (adbf.free_result(db_handle, db_res) < 0) {
LM_DBG("failed to freeing result of query\n");
+ }
return 1;
err_server:
- if (db_res!=NULL && adbf.free_result(db_handle, db_res) < 0)
- LM_DBG("failed to freeing result of query\n");
+ if (db_res!=NULL) {
+ if(adbf.free_result(db_handle, db_res) < 0) {
+ LM_DBG("failed to freeing result of query\n");
+ }
+ }
return -1;
}
More information about the sr-dev
mailing list