BUGFIX: NULL out wrong elements

This commit is contained in:
Alex D. 2020-12-22 17:33:21 +00:00
parent 10c5dfb400
commit 3849e65431
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 4 additions and 5 deletions

View File

@ -36,14 +36,13 @@ init_chanarray(Channel** chans)
signed int
resize_chanarray(Channel** chans)
{
unsigned int i = 0;
unsigned int i = get_channelindex(NULL, *chans);
Channel* tmp = NULL;
i = get_channelindex(NULL, *chans);
LOG(LOG_DEBUG, "Found %i existing channels.", i);
if ((tmp = realloc(*chans, (i + 2) * sizeof(Channel))) != NULL) {
*chans = tmp;
tmp[i].name = NULL;
tmp[i].key = NULL;
tmp[i+1].name = NULL;
tmp[i+1].key = NULL;
} else {
LOG(LOG_WARN, "Could not allocate channel struct. " ERRNOFMT, strerror(errno), errno);
return -1;

View File

@ -51,10 +51,10 @@ parse_configfile(char* config_path, Connection* conn)
config_setting_lookup_string(chanelem, "name", &name);
config_setting_lookup_string(chanelem, "key", &key);
LOG(LOG_DEBUG, "Got channel #%i: %s", i, name);
resize_chanarray(&conn->info.channels);
if (name != NULL) {
set_channel(&conn->info.channels[get_channelindex(name, conn->info.channels)], name, key, true);
}
resize_chanarray(&conn->info.channels);
}
}