Skip to content

Commit d7a3409

Browse files
committed
Enhance: systemic disposal of struct booth config
Signed-off-by: Jan Pokorný <[email protected]>
1 parent 0732349 commit d7a3409

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/config.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ int read_config(struct booth_config **conf_pptr,
536536
struct ticket_config *current_tk = NULL;
537537

538538
assert(conf_pptr != NULL);
539-
free(*conf_pptr);
539+
config_free(*conf_pptr);
540540

541541
fp = fopen(path, "r");
542542
if (!fp) {
@@ -899,11 +899,19 @@ int read_config(struct booth_config **conf_pptr,
899899
log_error("%s in config file line %d",
900900
error, lineno);
901901

902-
free(*conf_pptr);
902+
config_free(*conf_pptr);
903903
*conf_pptr = NULL;
904904
return -1;
905905
}
906906

907+
void config_free(struct booth_config *conf_ptr)
908+
{
909+
if (conf_ptr != NULL) {
910+
free(conf_ptr->ticket);
911+
}
912+
free(conf_ptr);
913+
}
914+
907915
int check_config(struct booth_config *conf_ptr, int type)
908916
{
909917
struct passwd *pw;

src/config.h

+10
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,21 @@ struct booth_config {
345345
* @param[in] type role currently being acted as
346346
*
347347
* @return 0 or negative value (-1 or -errno) on error
348+
*
349+
* @note To eventually dispose the associated memory, use #config_free.
348350
*/
349351
int read_config(struct booth_config **conf_pptr,
350352
const booth_transport_table_t *transport, const char *path,
351353
int type);
352354

355+
/**
356+
* @internal
357+
* Memory disposal for the config object
358+
*
359+
* @param[inout] conf_ptr config object to free
360+
*/
361+
void config_free(struct booth_config *conf_ptr);
362+
353363
/**
354364
* @internal
355365
* Check booth configuration

src/main.c

+2
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,8 @@ int main(int argc, char *argv[], char *envp[])
16381638
}
16391639

16401640
out:
1641+
config_free(booth_conf);
1642+
16411643
#ifdef LOGGING_LIBQB
16421644
qb_log_fini();
16431645
#endif

0 commit comments

Comments
 (0)