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 Jan 31, 2020
1 parent 0732349 commit d7a3409
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 @@ -536,7 +536,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 @@ -899,11 +899,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 @@ -345,11 +345,21 @@ 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 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 @@ -1638,6 +1638,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 d7a3409

Please sign in to comment.