speeddial: simplified access to db_res and the free of it
authorDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 21 Jul 2017 06:57:39 +0000 (08:57 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 21 Jul 2017 06:57:39 +0000 (08:57 +0200)
src/modules/speeddial/sdlookup.c

index c4f655e..d9e52bf 100644 (file)
@@ -161,17 +161,17 @@ int sd_lookup_owner(sip_msg_t* _msg, str* stable, str* sowner)
 
        db_funcs.use_table(db_handle, &table_s);
        if(db_funcs.query(db_handle, db_keys, NULL, db_vals, db_cols,
-               nr_keys /*no keys*/, 1 /*no cols*/, NULL, &db_res)!=0)
+               nr_keys /*no keys*/, 1 /*no cols*/, NULL, &db_res)!=0 || db_res==NULL)
        {
                LM_ERR("failed to query database\n");
                goto err_server;
        }
 
-       if (RES_ROW_N(db_res)<=0 || RES_ROWS(db_res)[0].values[0].nul != 0)
-       {
+       if(RES_ROW_N(db_res) <= 0 || RES_ROWS(db_res)[0].values[0].nul != 0) {
                LM_DBG("no sip address found for R-URI\n");
-               if (db_res!=NULL && db_funcs.free_result(db_handle, db_res) < 0)
+               if(db_funcs.free_result(db_handle, db_res) < 0) {
                        LM_DBG("failed to free result of query\n");
+               }
                return -1;
        }
 
@@ -199,8 +199,7 @@ int sd_lookup_owner(sip_msg_t* _msg, str* stable, str* sowner)
                break;
                default:
                        LM_ERR("unknown type of DB new_uri column\n");
-                       if (db_res != NULL && db_funcs.free_result(db_handle, db_res) < 0)
-                       {
+                       if (db_funcs.free_result(db_handle, db_res) < 0) {
                                LM_DBG("failed to free result of query\n");
                        }
                        goto err_server;
@@ -217,8 +216,9 @@ int sd_lookup_owner(sip_msg_t* _msg, str* stable, str* sowner)
        /**
         * Free the result because we don't need it anymore
         */
-       if (db_res!=NULL && db_funcs.free_result(db_handle, db_res) < 0)
+       if (db_funcs.free_result(db_handle, db_res) < 0) {
                LM_DBG("failed to free result of query\n");
+       }
 
        /* set the URI */
        LM_DBG("URI of sd from R-URI [%s]\n", user_s.s);