]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
fix tests and config memory leak
authorBastian Dehn <hhaalo@arcor.de>
Thu, 6 Mar 2025 18:34:49 +0000 (19:34 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 6 Mar 2025 18:34:49 +0000 (19:34 +0100)
CMakeLists.txt
src/kds_s2000w_config.c
src/kds_s2000w_handler.c
tests/kds_s2000w_client_mock.c
tests/kds_s2000w_client_mock.h

index 094d19f4488620dc707ea76991e7c507084ec755..6dd792be792906cb0a426c2dff6b75217c602299 100644 (file)
@@ -22,7 +22,9 @@ IF (RUN_TESTS)
 -Wall \
 -g \
 -fsanitize=address \
--Wl,--wrap,kds_s2000w_client_open_session,\
+-Wl,--wrap,kds_s2000w_client_init,\
+--wrap,kds_s2000w_client_free,\
+--wrap,kds_s2000w_client_open_session,\
 --wrap,kds_s2000w_client_close_session,\
 --wrap,kds_s2000w_client_start_scan,\
 --wrap,kds_s2000w_client_stop_scan,\
index 5d24782bdfb5b5da621e81eed7024e38f5ab6e14..10f5919eeadc575b9300db819c1731dd212a6ffa 100644 (file)
@@ -18,6 +18,10 @@ void _kds_s2000w_config_copy_string_to_config_value(cfg_t* cfg, const char* key,
 char* kds_s2000w_config_read(const char* filename)
 {
        FILE* config_file = fopen(filename, "r");
+
+       if (config_file == NULL)
+               return NULL;
+
        fseek(config_file, 0, SEEK_END);
        size_t config_size = ftell(config_file);
        rewind(config_file);
@@ -39,6 +43,7 @@ program_config* kds_s2000w_config_load(char* config_string)
        config->username = malloc(sizeof(char));
        *config->scanner_url = 0;
        *config->username = 0;
+       config->log_level = 0;
        config->heartbeat = 1;
        config->ssl_verify = 0;
 
@@ -49,8 +54,8 @@ program_config* kds_s2000w_config_load(char* config_string)
                return config;
 
        cfg_opt_t opts[] = {
-               CFG_STR("username", "", CFGF_NONE),
                CFG_STR("scanner_url", "", CFGF_NONE),
+               CFG_STR("username", "", CFGF_NONE),
                CFG_INT("default_log_level", 0, CFGF_NONE),
                CFG_INT("heartbeat_seconds", 1, CFGF_NONE),
                CFG_BOOL("ssl_verify", 0, CFGF_NONE),
index d41664f1da97c2e3d913b55cb731ae6e4dba2fe3..d082cc121a4a111278f01545353d399fb284dd9f 100644 (file)
@@ -37,6 +37,8 @@ uint32_t _kds_s2000w_handler_find_first_data_byte(imagedata* image)
 
 void _kds_s2000w_handler_load_config()
 {
+       kds_s2000w_debug_printf(ALL, "kds_s2000w_handler_load_config");
+
        char* config_stream = kds_s2000w_config_read(CONFIG_FILE);
        program_config* config = kds_s2000w_config_load(config_stream);
 
index 700ca514105a678525feadca12f4f94e8cac7cdd..23cf269d13ec8db0dd09a33c73ec9d91988dcad9 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -17,6 +18,16 @@ void mock_response(response* resp)
        resp->size = mock_resp->size;
 }
 
+void __wrap_kds_s2000w_client_init(const char* scanner_url, const char* username, bool ssl_verify, uint8_t heartbeat)
+{
+       return;
+}
+
+void __wrap_kds_s2000w_client_free()
+{
+       return;
+}
+
 uint8_t __wrap_kds_s2000w_client_open_session(response* response)
 {
        function_called();
index 3aa76235ba5b8082d3c983fb03992e151193315f..7103ebda43892a70c23d8aa8477c1a091872d12e 100644 (file)
@@ -10,7 +10,7 @@
 
 void mock_response(response* resp);
 
-void __wrap_kds_s2000w_client_init();
+void __wrap_kds_s2000w_client_init(const char* scanner_url, const char* username, bool ssl_verify, uint8_t heartbeat);
 void __wrap_kds_s2000w_client_free();
 
 uint8_t __wrap_kds_s2000w_client_open_session(response* response);