Make subscr parameter to db_subscr_get() optional
This allows to check for subscriber's presence in DB without the need to
bother with unused structure allocation.
While at it also call to db_remove_reset() and return explicitly instead
of using goto to make it a bit easier to follow the code.
Change-Id: I83b0f4a5dacb97614721690ef55bc1311624a58e
diff --git a/src/db_hlr.c b/src/db_hlr.c
index 2c6b243..340e7ce 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -41,7 +41,7 @@
struct hlr_subscriber *subscr)
{
sqlite3_stmt *stmt = dbc->stmt[SEL_BY_IMSI];
- int rc, ret = 0;
+ int rc;
if (!db_bind_imsi(stmt, imsi))
return -EINVAL;
@@ -50,8 +50,13 @@
rc = sqlite3_step(stmt);
if (rc != SQLITE_ROW) {
LOGHLR(imsi, LOGL_ERROR, "Error executing SQL: %d\n", rc);
- ret = -ENOEXEC;
- goto out;
+ db_remove_reset(stmt);
+ return -ENOEXEC;
+ }
+
+ if (!subscr) {
+ db_remove_reset(stmt);
+ return 0;
}
/* obtain the various columns */
@@ -70,10 +75,9 @@
subscr->ms_purged_cs = sqlite3_column_int(stmt, 11);
subscr->ms_purged_ps = sqlite3_column_int(stmt, 12);
-out:
db_remove_reset(stmt);
- return ret;
+ return 0;
}
int db_subscr_ps(struct db_context *dbc, const char *imsi, bool enable)