From 2016a6835480c5df055a9a1ce2a37ed35c245af7 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Mon, 19 Nov 2018 16:17:35 +0900 Subject: [PATCH] Remove dereference after null check and dead code Change-Id: Ie646658cdfb4cb2443161329f48087a0445d559b Signed-off-by: hyunuktak --- src/helper/helper-file.c | 11 ++++------- src/helper/helper-nfacct-rule.c | 18 ++++++------------ src/monitor/stc-monitor-app.c | 3 +++ src/monitor/stc-monitor-rstn.c | 6 ++++++ 4 files changed, 19 insertions(+), 19 deletions(-) mode change 100644 => 100755 src/helper/helper-file.c mode change 100644 => 100755 src/helper/helper-nfacct-rule.c diff --git a/src/helper/helper-file.c b/src/helper/helper-file.c old mode 100644 new mode 100755 index 73b93bd..636ef5d --- a/src/helper/helper-file.c +++ b/src/helper/helper-file.c @@ -24,17 +24,14 @@ int fwrite_str(const char *path, const char *str) _cleanup_fclose_ FILE *f = NULL; int ret; char * t; - struct stat stat_buf; assert(path); assert(str); - if (stat(path, &stat_buf) == 0) { - t = realpath(path, NULL); - ret_value_errno_msg_if(!t, -errno, - "Fail to get realpath %s", path); - free(t); - } + t = realpath(path, NULL); + ret_value_errno_msg_if(!t, -errno, + "Fail to get realpath %s", path); + free(t); f = fopen(path, "w"); ret_value_errno_msg_if(!f, -errno, diff --git a/src/helper/helper-nfacct-rule.c b/src/helper/helper-nfacct-rule.c old mode 100644 new mode 100755 index 4a80fca..fbe17ca --- a/src/helper/helper-nfacct-rule.c +++ b/src/helper/helper-nfacct-rule.c @@ -425,12 +425,9 @@ static char *get_iptables_chain(uint32_t classid, if (iotype == NFACCT_COUNTER_IN) { if (intend == NFACCT_COUNTER || intend == NFACCT_TETH_COUNTER) { - if (app_state == STC_APP_STATE_FOREGROUND) { - if (intend == NFACCT_ALLOW) - return STC_IN_ACCEPT_CHAIN; - else - return STC_IN_FG_CHAIN; - } else + if (app_state == STC_APP_STATE_FOREGROUND) + return STC_IN_FG_CHAIN; + else return STC_IN_BG_CHAIN; } else if (intend == NFACCT_ALLOW || intend == NFACCT_TETH_ALLOW) { @@ -444,12 +441,9 @@ static char *get_iptables_chain(uint32_t classid, } else if (iotype == NFACCT_COUNTER_OUT) { if (intend == NFACCT_COUNTER || intend == NFACCT_TETH_COUNTER) { - if (app_state == STC_APP_STATE_FOREGROUND) { - if (intend == NFACCT_ALLOW) - return STC_OUT_ACCEPT_CHAIN; - else - return STC_OUT_FG_CHAIN; - } else + if (app_state == STC_APP_STATE_FOREGROUND) + return STC_OUT_FG_CHAIN; + else return STC_OUT_BG_CHAIN; } else if (intend == NFACCT_ALLOW || intend == NFACCT_TETH_ALLOW) { diff --git a/src/monitor/stc-monitor-app.c b/src/monitor/stc-monitor-app.c index 6441593..96d602a 100644 --- a/src/monitor/stc-monitor-app.c +++ b/src/monitor/stc-monitor-app.c @@ -56,6 +56,9 @@ static void __app_update_statistics(gpointer key, memset(&stat_key, 0, sizeof(stc_db_classid_iftype_key)); memset(&stat, 0 , sizeof(stc_db_app_stats)); + if (conn == NULL) + return; + /* Do not update statistics for Tethering * if tethering is in-active found */ if (conn && conn->tether_state == FALSE && diff --git a/src/monitor/stc-monitor-rstn.c b/src/monitor/stc-monitor-rstn.c index ce3fa63..f28de3c 100644 --- a/src/monitor/stc-monitor-rstn.c +++ b/src/monitor/stc-monitor-rstn.c @@ -212,6 +212,9 @@ static void __rstn_add_ipt_rule(int64_t classid, nfacct_rule_intend intend, for (; conn_list != NULL; conn_list = conn_list->next) { stc_connection_s *conn = conn_list->data; + if (conn == NULL) + return; + if (!stc->carg) { stc->carg = MALLOC0(counter_arg_s, 1); if (stc->carg == NULL) @@ -258,6 +261,9 @@ static void __rstn_del_ipt_rule(int64_t classid, nfacct_rule_intend intend, for (; conn_list != NULL; conn_list = conn_list->next) { stc_connection_s *conn = conn_list->data; + if (conn == NULL) + return; + if (!stc->carg) { stc->carg = MALLOC0(counter_arg_s, 1); if (stc->carg == NULL) -- 2.7.4