Skip to content

Commit

Permalink
snmpstats: free space in case of error
Browse files Browse the repository at this point in the history
Fixes Coverity CID 40799, 40800, 40801, 40804, 40811, 40814, 40817, 40818

(cherry picked from commit 9b64078ada10287848d6f5853cc5c4cc3dc1b0fb)
  • Loading branch information
razvancrainea committed Nov 14, 2016
1 parent da25143 commit d1255bf
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/snmpstats/openserSIPCommonObjects.c
Expand Up @@ -234,8 +234,10 @@ int handle_openserSIPServiceStartTime(netsnmp_mib_handler *handler,
LM_ERR("failed to read sysUpTime file at %s\n",
SNMPGET_TEMP_FILE);
} else {
if (fgets(buffer, SNMPGET_MAX_BUFFER, theFile)==NULL)
if (fgets(buffer, SNMPGET_MAX_BUFFER, theFile)==NULL) {
fclose(theFile);
return SNMP_ERR_GENERR;
}

/* Find the positions of '(' and ')' so we can extract out the
* timeticks value. */
Expand Down
2 changes: 2 additions & 0 deletions modules/snmpstats/openserSIPContactTable.c
Expand Up @@ -301,6 +301,8 @@ void initialize_table_openserSIPContactTable(void)
if (!my_handler || !table_info) {
snmp_log(LOG_ERR, "malloc failed in initialize_table_openser"
"SIPContactTable_handler\n");
if (table_info)
SNMP_FREE(table_info);
return; /** mallocs failed */
}

Expand Down
3 changes: 3 additions & 0 deletions modules/snmpstats/openserSIPMethodSupportedTable.c
Expand Up @@ -88,6 +88,7 @@ void createRow(int index, char *stringToRegister) {
copiedString = pkg_malloc((stringLength + 1) * sizeof(char));

if (copiedString == NULL) {
SNMP_FREE(theRow);
LM_ERR("failed to create a row for openserSIPMethodSupportedTable\n");
return;
}
Expand Down Expand Up @@ -200,6 +201,8 @@ void initialize_table_openserSIPMethodSupportedTable(void)
if (!my_handler || !table_info) {
snmp_log(LOG_ERR, "malloc failed in initialize_table_openser"
"SIPMethodSupportedTable_handler\n");
if (table_info)
SNMP_FREE(table_info);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions modules/snmpstats/openserSIPPortTable.c
Expand Up @@ -270,6 +270,8 @@ void initialize_table_openserSIPPortTable(void)
if (!my_handler || !table_info) {
snmp_log(LOG_ERR, "malloc failed in "
"initialize_table_openserSIPPortTable_handler\n");
if (table_info)
SNMP_FREE(table_info);
return; /** mallocs failed */
}

Expand Down
2 changes: 2 additions & 0 deletions modules/snmpstats/openserSIPRegUserLookupTable.c
Expand Up @@ -705,6 +705,8 @@ void initialize_table_openserSIPRegUserLookupTable(void)
snmp_log(LOG_ERR, "malloc failed in "
"initialize_table_openserSIPRegUserLookup"
"Table_handler\n");
if (table_info)
SNMP_FREE(table_info);
return; /** mallocs failed */
}

Expand Down
2 changes: 2 additions & 0 deletions modules/snmpstats/openserSIPRegUserTable.c
Expand Up @@ -321,6 +321,8 @@ void initialize_table_openserSIPRegUserTable(void)
if (!my_handler || !table_info) {
snmp_log(LOG_ERR, "malloc failed in initialize_table_openser"
"SIPRegUserTable_handler\n");
if (table_info)
SNMP_FREE(table_info);
return; /** mallocs failed */
}

Expand Down
2 changes: 2 additions & 0 deletions modules/snmpstats/openserSIPStatusCodesTable.c
Expand Up @@ -682,6 +682,8 @@ void initialize_table_openserSIPStatusCodesTable(void)
if (!my_handler || !table_info) {
snmp_log(LOG_ERR, "malloc failed in initialize_table_openserSIP"
"StatusCodesTable_handler\n");
if (table_info)
SNMP_FREE(table_info);
return; /** mallocs failed */
}

Expand Down

0 comments on commit d1255bf

Please sign in to comment.