Remove dereference after null check and dead code 13/193313/2
authorhyunuktak <hyunuk.tak@samsung.com>
Mon, 19 Nov 2018 07:17:35 +0000 (16:17 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Mon, 19 Nov 2018 07:43:43 +0000 (16:43 +0900)
Change-Id: Ie646658cdfb4cb2443161329f48087a0445d559b
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
src/helper/helper-file.c [changed mode: 0644->0755]
src/helper/helper-nfacct-rule.c [changed mode: 0644->0755]
src/monitor/stc-monitor-app.c
src/monitor/stc-monitor-rstn.c

old mode 100644 (file)
new mode 100755 (executable)
index 73b93bd..636ef5d
@@ -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,
old mode 100644 (file)
new mode 100755 (executable)
index 4a80fca..fbe17ca
@@ -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) {
index 6441593..96d602a 100644 (file)
@@ -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 &&
index ce3fa63..f28de3c 100644 (file)
@@ -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)