From: Christian Göttsche Date: Fri, 6 Sep 2019 15:51:53 +0000 (+0200) Subject: fix resource leak in db_getdata_range X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b9cd06a38c516a3f36fddf2fc1da31591f13811a;p=vnstat fix resource leak in db_getdata_range if an invalid 'table' is given the function returns without freeing 'ifaceidin' postpone the initialization found by Coverity --- diff --git a/src/dbsql.c b/src/dbsql.c index 9fb8135..12fd51b 100644 --- a/src/dbsql.c +++ b/src/dbsql.c @@ -1171,11 +1171,6 @@ int db_getdata_range(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char * listinfo->count = 0; - ifaceidin = db_getinterfaceidin(iface); - if (ifaceidin == NULL) { - return 0; - } - ret = 0; for (i = 0; i < 6; i++) { if (strcmp(table, datatables[i]) == 0) { @@ -1187,6 +1182,11 @@ int db_getdata_range(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char * return 0; } + ifaceidin = db_getinterfaceidin(iface); + if (ifaceidin == NULL) { + return 0; + } + dbegin[0] = '\0'; if (strlen(databegin)) { snprintf(dbegin, 32, "and date >= '%s'", databegin);