Mercurial > dovecot > core-2.2
changeset 20590:0daaebf5fd55
dict-client: Fixed error message for failed synchronous dict_lookup()
The error message was allocated from data stack, but freed too early.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Fri, 05 Aug 2016 22:57:02 +0300 |
parents | bdf83b32af07 |
children | 07fa25c2da86 |
files | src/lib-dict/dict-client.c |
diffstat | 1 files changed, 18 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-dict/dict-client.c Thu Aug 04 21:44:08 2016 +0300 +++ b/src/lib-dict/dict-client.c Fri Aug 05 22:57:02 2016 +0300 @@ -745,35 +745,43 @@ client_dict_cmd_send(dict, &cmd, NULL); } +struct client_dict_sync_lookup { + struct dict_lookup_result result; + char *error; +}; + static void client_dict_lookup_callback(const struct dict_lookup_result *result, void *context) { - struct dict_lookup_result *result_copy = context; + struct client_dict_sync_lookup *lookup = context; - *result_copy = *result; + lookup->result = *result; + if (result->ret == -1) + lookup->error = i_strdup(result->error); } static int client_dict_lookup(struct dict *_dict, pool_t pool, const char *key, const char **value_r) { - struct dict_lookup_result result; + struct client_dict_sync_lookup lookup; - memset(&result, 0, sizeof(result)); - result.ret = -2; + memset(&lookup, 0, sizeof(lookup)); + lookup.result.ret = -2; - client_dict_lookup_async(_dict, key, client_dict_lookup_callback, &result); - if (result.ret == -2) + client_dict_lookup_async(_dict, key, client_dict_lookup_callback, &lookup); + if (lookup.result.ret == -2) client_dict_wait(_dict); - switch (result.ret) { + switch (lookup.result.ret) { case -1: - i_error("dict-client: Lookup '%s' failed: %s", key, result.error); + i_error("dict-client: Lookup '%s' failed: %s", key, lookup.error); + i_free(lookup.error); return -1; case 0: *value_r = NULL; return 0; case 1: - *value_r = p_strdup(pool, result.value); + *value_r = p_strdup(pool, lookup.result.value); return 1; } i_unreached();