program_config* _kds_s2000w_config_init()
{
program_config* config = malloc(sizeof(program_config));
+ if (config == NULL)
+ return NULL;
config->scanner_url = malloc(sizeof(char));
config->username = malloc(sizeof(char));
char* value_str = cfg_getstr(cfg, key);
size_t length = strlen(value_str) + 1;
char* new_str = malloc(sizeof(char) * length);
- new_str = strncpy(new_str, value_str, length);
+ if (new_str == NULL)
+ return NULL;
+ new_str = strncpy(new_str, value_str, length);
return new_str;
}
char* kds_s2000w_config_read(const char* filename)
{
FILE* config_file = fopen(filename, "r");
-
if (config_file == NULL)
return NULL;
rewind(config_file);
char* config_string = malloc(sizeof(char) * config_size + 1);
+ if (config_string == NULL) {
+ fclose(config_file);
+ return NULL;
+ }
+
fread(config_string, config_size, 1, config_file);
config_string[config_size] = '\0';
program_config* kds_s2000w_config_load(char* config_string)
{
program_config* config = _kds_s2000w_config_init();
+ if (config == NULL)
+ return NULL;
if (config_string == NULL)
return config;
kds_s2000w_debug_printf(ALL, "kds_s2000w_handler_load_config");
char* config_stream = kds_s2000w_config_read(CONFIG_FILE);
+ if (config_stream == NULL)
+ return;
+
program_config* config = kds_s2000w_config_load(config_stream);
+ if (config == NULL)
+ return;
kds_s2000w_client_init(config->scanner_url,
config->username,