Skip to content

Commit

Permalink
lib-master: master_service_init_finish() now verifies that t_pop() wa…
Browse files Browse the repository at this point in the history
…sn't leaked
  • Loading branch information
sirainen authored and GitLab committed Sep 2, 2016
1 parent e258887 commit 28bf8f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/lib-master/master-service-private.h
Expand Up @@ -34,6 +34,7 @@ struct master_service {
ARRAY_TYPE(const_string) config_overrides;
int config_fd;
int syslog_facility;
data_stack_frame_t datastack_frame_id;

struct master_service_listener *listeners;
unsigned int socket_count;
Expand Down
10 changes: 7 additions & 3 deletions src/lib-master/master-service.c
Expand Up @@ -152,6 +152,7 @@ master_service_init(const char *name, enum master_service_flags flags,
int *argc, char **argv[], const char *getopt_str)
{
struct master_service *service;
data_stack_frame_t datastack_frame_id = 0;
unsigned int count;
const char *value;

Expand Down Expand Up @@ -186,7 +187,7 @@ master_service_init(const char *name, enum master_service_flags flags,
before we get to ioloop. the corresponding t_pop() is in
master_service_init_finish(). */
if ((flags & MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME) == 0)
t_push(NULL);
datastack_frame_id = t_push(NULL);

/* ignore these signals as early as possible */
lib_signals_init();
Expand All @@ -210,6 +211,7 @@ master_service_init(const char *name, enum master_service_flags flags,
service->ioloop = io_loop_create();
service->service_count_left = UINT_MAX;
service->config_fd = -1;
service->datastack_frame_id = datastack_frame_id;

service->config_path = i_strdup(getenv(MASTER_CONFIG_FILE_ENV));
if (service->config_path == NULL)
Expand Down Expand Up @@ -532,8 +534,10 @@ void master_service_init_finish(struct master_service *service)
master_status_update(service);

/* close data stack frame opened by master_service_init() */
if ((service->flags & MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME) == 0)
t_pop();
if ((service->flags & MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME) == 0) {
if (t_pop() != service->datastack_frame_id)
i_panic("Leaked t_pop() call");
}
}

void master_service_env_clean(void)
Expand Down

0 comments on commit 28bf8f7

Please sign in to comment.