From: Timo Sirainen Date: Mon, 19 Jul 2010 16:37:55 +0000 (+0100) Subject: auth: Make sure userdb iteration doesn't free memory too early if it's aborted. X-Git-Tag: 2.0.rc3~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1aad8ad0590bee2d09d5fdb5413af72e2a8e156a;p=thirdparty%2Fdovecot%2Fcore.git auth: Make sure userdb iteration doesn't free memory too early if it's aborted. --- diff --git a/src/auth/userdb-blocking.c b/src/auth/userdb-blocking.c index c70e1d2be1..fd81179d7b 100644 --- a/src/auth/userdb-blocking.c +++ b/src/auth/userdb-blocking.c @@ -65,19 +65,19 @@ void userdb_blocking_lookup(struct auth_request *request) static bool iter_callback(const char *reply, void *context) { struct blocking_userdb_iterate_context *ctx = context; + pool_t pool = ctx->pool; if (strncmp(reply, "*\t", 2) == 0) { ctx->next = FALSE; ctx->ctx.callback(reply + 2, ctx->ctx.context); return ctx->next; - } else if (strcmp(reply, "OK") == 0) { - ctx->ctx.callback(NULL, ctx->ctx.context); - return TRUE; - } else { - ctx->ctx.failed = TRUE; - ctx->ctx.callback(NULL, ctx->ctx.context); - return TRUE; } + + if (strcmp(reply, "OK") != 0) + ctx->ctx.failed = TRUE; + ctx->ctx.callback(NULL, ctx->ctx.context); + pool_unref(&pool); + return TRUE; } struct userdb_iterate_context * @@ -99,6 +99,7 @@ userdb_blocking_iter_init(struct userdb_module *userdb, ctx->ctx.context = context; ctx->pool = pool; + pool_ref(pool); ctx->conn = auth_worker_call(pool, reply, iter_callback, ctx); return &ctx->ctx; }