Skip to content

Commit

Permalink
doveadm: Fixed memory leaks when ver2 command parsing fails with inva…
Browse files Browse the repository at this point in the history
…lid parameter.
  • Loading branch information
sirainen committed Feb 22, 2016
1 parent 1360790 commit f8e3a08
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/doveadm/doveadm-mail.c
Expand Up @@ -596,12 +596,16 @@ doveadm_mail_cmd_exec(struct doveadm_mail_cmd_context *ctx,
/* service deinit unloads mail plugins, so do it late */
mail_storage_service_deinit(&ctx->storage_service);

if (ctx->exit_code != 0)
doveadm_exit_code = ctx->exit_code;
}

static void doveadm_mail_cmd_free(struct doveadm_mail_cmd_context *ctx)
{
if (ctx->users_list_input != NULL)
i_stream_unref(&ctx->users_list_input);
if (ctx->cmd_input != NULL)
i_stream_unref(&ctx->cmd_input);
if (ctx->exit_code != 0)
doveadm_exit_code = ctx->exit_code;
pool_unref(&ctx->pool);
}

Expand Down Expand Up @@ -662,6 +666,7 @@ doveadm_mail_cmd(const struct doveadm_mail_cmd *cmd, int argc, char *argv[])
}
ctx->args = (const void *)argv;
doveadm_mail_cmd_exec(ctx, wildcard_user);
doveadm_mail_cmd_free(ctx);
}

static bool
Expand Down Expand Up @@ -939,6 +944,7 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(const struct doveadm_cmd_ver2* cmd,
} else {
doveadm_exit_code = EX_USAGE;
i_error("invalid parameter: %s", argv[i].name);
doveadm_mail_cmd_free(ctx);
return -1;
}
}
Expand All @@ -948,5 +954,6 @@ doveadm_cmd_ver2_to_mail_cmd_wrapper(const struct doveadm_cmd_ver2* cmd,
ctx->full_args = ctx->args;

doveadm_mail_cmd_exec(ctx, wildcard_user);
doveadm_mail_cmd_free(ctx);
return 0;
}

0 comments on commit f8e3a08

Please sign in to comment.