From e4ceb1d8063a96b8634cc2c70191ab978766501e Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Wed, 27 Dec 2017 09:18:46 +0100 Subject: [PATCH] snmpstats: free allocated vars in case of error during init snmp tables (cherry picked from commit 4d4c91a709aff0b9b15fcc02b44de2106e65903e) (cherry picked from commit 7e8e7e57608e54de4b81c7522cbec89cc89bcb4c) --- src/modules/snmpstats/snmpSIPContactTable.c | 7 ++++++- src/modules/snmpstats/snmpSIPMethodSupportedTable.c | 7 ++++++- src/modules/snmpstats/snmpSIPPortTable.c | 7 ++++++- src/modules/snmpstats/snmpSIPRegUserLookupTable.c | 7 ++++++- src/modules/snmpstats/snmpSIPRegUserTable.c | 7 ++++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/modules/snmpstats/snmpSIPContactTable.c b/src/modules/snmpstats/snmpSIPContactTable.c index 582d5d6634b..77f497dce32 100644 --- a/src/modules/snmpstats/snmpSIPContactTable.c +++ b/src/modules/snmpstats/snmpSIPContactTable.c @@ -290,12 +290,17 @@ void initialize_table_kamailioSIPContactTable(void) /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); + if(table_info==NULL) { + snmp_log(LOG_ERR, "failed to allocate table_info\n"); + return; + } my_handler = netsnmp_create_handler_registration("kamailioSIPContactTable", netsnmp_table_array_helper_handler, kamailioSIPContactTable_oid, kamailioSIPContactTable_oid_len, HANDLER_CAN_RONLY); - if(!my_handler || !table_info) { + if(!my_handler) { + SNMP_FREE(table_info); snmp_log(LOG_ERR, "malloc failed in initialize_table_kamailio" "SIPContactTable_handler\n"); return; /** mallocs failed */ diff --git a/src/modules/snmpstats/snmpSIPMethodSupportedTable.c b/src/modules/snmpstats/snmpSIPMethodSupportedTable.c index 4dc3394dbee..f78cf56a1b1 100644 --- a/src/modules/snmpstats/snmpSIPMethodSupportedTable.c +++ b/src/modules/snmpstats/snmpSIPMethodSupportedTable.c @@ -176,6 +176,10 @@ void initialize_table_kamailioSIPMethodSupportedTable(void) /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); + if(table_info==NULL) { + snmp_log(LOG_ERR, "failed to allocate table_info\n"); + return; + } my_handler = netsnmp_create_handler_registration( "kamailioSIPMethodSupportedTable", @@ -183,7 +187,8 @@ void initialize_table_kamailioSIPMethodSupportedTable(void) kamailioSIPMethodSupportedTable_oid, kamailioSIPMethodSupportedTable_oid_len, HANDLER_CAN_RONLY); - if(!my_handler || !table_info) { + if(!my_handler) { + SNMP_FREE(table_info); snmp_log(LOG_ERR, "malloc failed in initialize_table_kamailio" "SIPMethodSupportedTable_handler\n"); return; diff --git a/src/modules/snmpstats/snmpSIPPortTable.c b/src/modules/snmpstats/snmpSIPPortTable.c index 3dcdf7ff93d..0d2755dc2c0 100644 --- a/src/modules/snmpstats/snmpSIPPortTable.c +++ b/src/modules/snmpstats/snmpSIPPortTable.c @@ -307,12 +307,17 @@ void initialize_table_kamailioSIPPortTable(void) /* create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); + if(table_info==NULL) { + snmp_log(LOG_ERR, "failed to allocate table_info\n"); + return; + } my_handler = netsnmp_create_handler_registration("kamailioSIPPortTable", netsnmp_table_array_helper_handler, kamailioSIPPortTable_oid, kamailioSIPPortTable_oid_len, HANDLER_CAN_RONLY); - if(!my_handler || !table_info) { + if(!my_handler) { + SNMP_FREE(table_info); snmp_log(LOG_ERR, "malloc failed in " "initialize_table_kamailioSIPPortTable_handler\n"); return; /** mallocs failed */ diff --git a/src/modules/snmpstats/snmpSIPRegUserLookupTable.c b/src/modules/snmpstats/snmpSIPRegUserLookupTable.c index d25392f35ba..8c41dab4efc 100644 --- a/src/modules/snmpstats/snmpSIPRegUserLookupTable.c +++ b/src/modules/snmpstats/snmpSIPRegUserLookupTable.c @@ -653,13 +653,18 @@ void initialize_table_kamailioSIPRegUserLookupTable(void) /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); + if(table_info==NULL) { + snmp_log(LOG_ERR, "failed to allocate table_info\n"); + return; + } my_handler = netsnmp_create_handler_registration( "kamailioSIPRegUserLookupTable", netsnmp_table_array_helper_handler, kamailioSIPRegUserLookupTable_oid, kamailioSIPRegUserLookupTable_oid_len, HANDLER_CAN_RWRITE); - if(!my_handler || !table_info) { + if(!my_handler) { + SNMP_FREE(table_info); snmp_log(LOG_ERR, "malloc failed in " "initialize_table_kamailioSIPRegUserLookup" "Table_handler\n"); diff --git a/src/modules/snmpstats/snmpSIPRegUserTable.c b/src/modules/snmpstats/snmpSIPRegUserTable.c index 63cf2f40ff4..4ad5bf33072 100644 --- a/src/modules/snmpstats/snmpSIPRegUserTable.c +++ b/src/modules/snmpstats/snmpSIPRegUserTable.c @@ -297,12 +297,17 @@ void initialize_table_kamailioSIPRegUserTable(void) /* create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); + if(table_info==NULL) { + snmp_log(LOG_ERR, "failed to allocate table_info\n"); + return; + } my_handler = netsnmp_create_handler_registration("kamailioSIPRegUserTable", netsnmp_table_array_helper_handler, kamailioSIPRegUserTable_oid, kamailioSIPRegUserTable_oid_len, HANDLER_CAN_RONLY); - if(!my_handler || !table_info) { + if(!my_handler) { + SNMP_FREE(table_info); snmp_log(LOG_ERR, "malloc failed in initialize_table_kamailio" "SIPRegUserTable_handler\n"); return; /** mallocs failed */