Free config data and close fd before terminated 14/114414/9 accepted/tizen/3.0/common/20170216.151325 accepted/tizen/3.0/ivi/20170216.060630 accepted/tizen/3.0/mobile/20170216.060515 accepted/tizen/3.0/tv/20170216.060533 accepted/tizen/3.0/wearable/20170216.060559 submit/tizen_3.0/20170215.023852
authorKichan Kwon <k_c.kwon@samsung.com>
Mon, 13 Feb 2017 08:41:06 +0000 (17:41 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 15 Feb 2017 02:10:03 +0000 (11:10 +0900)
Change-Id: Ib448c1901a4bff6c960bf1a8c26de7a4a350f39c
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/libdlog/log_android.c
src/libdlog/log_kmsg.c
src/libdlog/log_pipe.c
src/logctrl/logctrl.c
src/logutil/logutil.c

index 78ccfc8..2dacb0f 100644 (file)
@@ -74,19 +74,15 @@ void __dlog_init_android()
                        char err_message[MAX_CONF_VAL_LEN + 64];
                        snprintf(err_message, MAX_CONF_VAL_LEN + 64, "LOG BUFFER #%d %s HAS NO PATH SET IN CONFIG", buf_id, log_name_by_id(buf_id));
                        syslog_critical_failure(err_message);
-                       write_to_log = __write_to_log_null;
-                       return;
+                       goto failure;
                }
 
                log_fds[buf_id] = open(buffer_name, O_WRONLY);
        }
 
-       log_config_free(&conf);
-
        if (log_fds[LOG_ID_MAIN] < 0) {
                syslog_critical_failure("COULD NOT OPEN MAIN LOG");
-               write_to_log = __write_to_log_null;
-               return;
+               goto failure;
        }
 
        for (buf_id = 0; buf_id < LOG_ID_MAX; ++buf_id)
@@ -94,5 +90,17 @@ void __dlog_init_android()
                        log_fds[buf_id] = log_fds[LOG_ID_MAIN];
 
        write_to_log = __write_to_log_android;
+       goto cleanup;
+
+failure:
+       for (; buf_id >= 0; buf_id--) {
+               if (log_fds[buf_id] >= 0)
+                       close(log_fds[buf_id]);
+       }
+       write_to_log = __write_to_log_null;
+
+cleanup:
+       log_config_free(&conf);
+       return;
 }
 
index d7fcb08..2841844 100644 (file)
@@ -81,19 +81,15 @@ void __dlog_init_kmsg()
                        char err_message[MAX_CONF_VAL_LEN + 64];
                        snprintf(err_message, MAX_CONF_VAL_LEN + 64, "LOG BUFFER #%d %s HAS NO PATH SET IN CONFIG", buf_id, log_name_by_id(buf_id));
                        syslog_critical_failure(err_message);
-                       write_to_log = __write_to_log_null;
-                       return;
+                       goto failure;
                }
 
                log_fds[buf_id] = open(buffer_name, O_WRONLY);
        }
 
-       log_config_free(&conf);
-
        if (log_fds[LOG_ID_MAIN] < 0) {
                syslog_critical_failure("COULD NOT OPEN MAIN LOG");
-               write_to_log = __write_to_log_null;
-               return;
+               goto failure;
        }
 
        for (buf_id = 0; buf_id < LOG_ID_MAX; ++buf_id)
@@ -101,5 +97,17 @@ void __dlog_init_kmsg()
                        log_fds[buf_id] = log_fds[LOG_ID_MAIN];
 
        write_to_log = __write_to_log_kmsg;
+       goto cleanup;
+
+failure:
+       for (; buf_id >= 0; buf_id--) {
+               if (log_fds[buf_id] >= 0)
+                       close(log_fds[buf_id]);
+       }
+       write_to_log = __write_to_log_null;
+
+cleanup:
+       log_config_free(&conf);
+       return;
 }
 
index d79766f..6935a81 100644 (file)
@@ -175,6 +175,7 @@ void __dlog_init_pipe()
                if (!conf_val) {
                        syslog_critical_failure("DLog config lacks the \"%s\" entry!");
                        write_to_log = __write_to_log_null;
+                       log_config_free(&conf);
                        return;
                }
                snprintf(log_pipe_path[i], PATH_MAX, "%s", conf_val);
index b533f91..2fb29df 100644 (file)
@@ -108,19 +108,19 @@ int main(int argc, char ** argv)
        backend = log_config_get(&conf_etc, "backend");
        if (!backend) {
                printf("Error: there is no backend information\n");
-               return 1;
+               goto cleanup;
        }
 
        if (opt.help) {
                print_extended_help(backend);
-               return 1;
+               goto cleanup;
        }
 
        conf = &conf_etc;
        if (!strncmp(backend, "kmsg", sizeof("kmsg") + 1)) {
                if (log_config_read_file(&conf_run, KMSG_CONFIG_PATH) < 0) {
                        printf("Error: cannot open the config file!\n");
-                       return 1;
+                       goto cleanup;
                }
 
                /* keys existing only in the conf_run will be stored in the /run */
@@ -148,16 +148,22 @@ int main(int argc, char ** argv)
                        goto err_save;
        } else {
                printf("Error: invalid options\n");
-               return 1;
+               goto cleanup;
        }
 
+       log_config_free(&conf_run);
+       log_config_free(&conf_etc);
        return 0;
 
 err_save:
        printf("Cannot save file\n");
-       return 1;
+       goto cleanup;
 
 err_entry:
        printf("Entry not found\n");
+
+cleanup:
+       log_config_free(&conf_run);
+       log_config_free(&conf_etc);
        return 1;
 }
index 3d64449..e4b9de9 100644 (file)
@@ -838,6 +838,7 @@ int main(int argc, char ** argv)
        logs.data = (struct logger_entry**)calloc(sort_buffer_size, sizeof(struct logger_entry*));
        if (!(logs.data)) {
                printf("Failed to allocate sort buffer\n");
+               log_config_free(&conf);
                return 1;
        }
 
@@ -847,12 +848,14 @@ int main(int argc, char ** argv)
                        free(buffer_names[i]);
                for (i = 0; i < files_cnt; ++i)
                        free(file_input_names[i]);
+               log_config_free(&conf);
                return ret;
        }
 
        conf_value = log_config_get(&conf, "backend");
        if (!conf_value) {
                printf("Error: backend not defined\n");
+               log_config_free(&conf);
                return 1;
        }
 
@@ -860,6 +863,7 @@ int main(int argc, char ** argv)
                l_file.fd = open(l_file.path, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
                if (l_file.fd < 0) {
                        printf("Failed to open %s", l_file.path);
+                       log_config_free(&conf);
                        return 1;
                }