fix: ensure log_config is always properly initialized 64/196464/3
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 28 Dec 2018 15:17:03 +0000 (16:17 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Sun, 30 Dec 2018 00:59:08 +0000 (00:59 +0000)
Proper initialization is required to be able to free the
structure after eg. failing log_config_read() which might
have either read some entries (and updated .begin/.end)
or have not read anything (keeping .begin/.end unchanged).

Change-Id: I3a2a2434488e13349746a85afcb4c81752609dd9

src/libdlog/log.c
src/logger/logger.c
src/tests/config.c

index fb499fa..8c293ac 100644 (file)
@@ -155,24 +155,21 @@ void __update_plog(const struct log_config *conf)
  */
 static void __configure(void)
 {
-       struct log_config config;
+       struct log_config config = {.begin = NULL, .last = NULL};
 
        if (log_config_read(&config) < 0)
-               goto failure;
+               goto out;
 
        dynamic_config = __dynamic_config_create(&config);
 
        __configure_parameters(&config);
 
        if (!__configure_backend(&config))
-               goto failure;
+               goto out;
 
        __configure_limiter(&config);
 
-       log_config_free(&config);
-       return;
-
-failure:
+out:
        log_config_free(&config);
        return;
 }
index ddf8507..3a7fd3a 100644 (file)
@@ -2112,10 +2112,10 @@ int prepare_config_data(struct logger_config_data *data, int argc, char **argv)
                return ret;
        }
 
-       struct log_config conf;
+       struct log_config conf = {.begin = NULL, .last = NULL};
        ret = log_config_read(&conf);
        if (ret < 0)
-               return ret;
+               goto end;
 
        const enum sorting_order sort_by = get_order_from_config(&conf);
 
index 0f36ff0..ab1b932 100644 (file)
@@ -53,7 +53,7 @@ int __wrap_open(const char *pathname, int flags, mode_t mode)
 int main()
 {
        const char * get;
-       struct log_config config;
+       struct log_config config = {.begin = NULL, .last = NULL};
 
        setenv("DLOG_CONFIG_PATH", "./non_existent_file", 1);
        assert(log_config_read(&config) == -ENOENT);