Skip to content

Commit

Permalink
Enhance: systemic disposal of struct booth config
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Pokorný <[email protected]>
  • Loading branch information
jnpkrn committed Feb 11, 2020
1 parent f1b1390 commit 784a765
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ int read_config(struct booth_config **conf_pptr,
struct ticket_config *current_tk = NULL;

assert(conf_pptr != NULL);
free(*conf_pptr);
config_free(*conf_pptr);

fp = fopen(path, "r");
if (!fp) {
Expand Down Expand Up @@ -901,11 +901,19 @@ int read_config(struct booth_config **conf_pptr,
log_error("%s in config file line %d",
error, lineno);

free(*conf_pptr);
config_free(*conf_pptr);
*conf_pptr = NULL;
return -1;
}

void config_free(struct booth_config *conf_ptr)
{
if (conf_ptr != NULL) {
free(conf_ptr->ticket);
}
free(conf_ptr);
}

int check_config(struct booth_config *conf_ptr, int type)
{
struct passwd *pw;
Expand Down
10 changes: 10 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,22 @@ struct booth_config {
* @param[in] type role currently being acted as
*
* @return 0 or negative value (-1 or -errno) on error
*
* @note To eventually dispose the associated memory, use #config_free.
*/
int read_config(struct booth_config **conf_pptr,
const booth_transport_table_t *transport,
const struct ticket_handler *ticket_handler,
const char *path, int type);

/**
* @internal
* Memory disposal for the config object
*
* @param[inout] conf_ptr config object to free
*/
void config_free(struct booth_config *conf_ptr);

/**
* @internal
* Check booth configuration
Expand Down
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,8 @@ int main(int argc, char *argv[], char *envp[])
}

out:
config_free(booth_conf);

#ifdef LOGGING_LIBQB
qb_log_fini();
#endif
Expand Down

0 comments on commit 784a765

Please sign in to comment.