X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcconfig.c;h=2066f95719ed0531315ffaebdc7bb2e9d8c36346;hp=1f3e4699fdf79d20891961d4463f4b507dd69a73;hb=ecb19b3983b3e74bc4aaa82277abd125c53c3623;hpb=382d15d447b7a95390decfa783836ae4fe255b3d diff --git a/lib/silcutil/silcconfig.c b/lib/silcutil/silcconfig.c index 1f3e4699..2066f957 100644 --- a/lib/silcutil/silcconfig.c +++ b/lib/silcutil/silcconfig.c @@ -2,9 +2,9 @@ silcconfig.c - Author: Johnny Mnemonic + Author: Giovanni Giacobbi - Copyright (C) 1997 - 2002 Pekka Riikonen + Copyright (C) 2002 - 2003 Giovanni Giacobbi This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -172,7 +172,8 @@ static SilcConfigOption *silc_config_find_option(SilcConfigEntity ent, } return NULL; } -/* ... */ +/* Converts a string in the type specified. returns a dynamically + * allocated pointer. */ static void *silc_config_marshall(SilcConfigType type, const char *val) { void *pt; @@ -578,7 +579,7 @@ static int silc_config_main_internal(SilcConfigEntity ent) } else { void *pt; - int ret; + int ret = 0; /* very important in case of no cb */ if (*(*p)++ != '=') return SILC_CONFIG_EEXPECTEDEQUAL; @@ -594,15 +595,17 @@ static int silc_config_main_internal(SilcConfigEntity ent) pt = silc_config_marshall(thisopt->type, buf); if (!pt) return SILC_CONFIG_EINVALIDTEXT; - if (thisopt->cb) { + if (thisopt->cb) ret = thisopt->cb(thisopt->type, thisopt->name, file->line, pt, thisopt->context); - if (ret) { - SILC_CONFIG_DEBUG(("Callback refused the value [ret=%d]", ret)); - return ret; - } - } + + /* since we have to free "pt" both on failure and on success, we + assume that ret == 0 if we didn't actually call any cb. */ silc_free(pt); + if (ret) { + SILC_CONFIG_DEBUG(("Callback refused the value [ret=%d]", ret)); + return ret; + } } continue;