
On 03/23/2012 08:16 PM, Daniel P. Berrange wrote:
On Thu, Mar 22, 2012 at 05:34:54PM +0800, Osier Yang wrote:
On 2012年03月21日 01:33, Daniel P. Berrange wrote:
From: "Daniel P. Berrange"<berrange@redhat.com> +static int virKeyFileParseValue(virKeyFileParserCtxtPtr ctxt) +{ + int ret = -1; + const char *keystart; + const char *valuestart; + char *key = NULL; + char *value = NULL; + size_t len; + + if (!ctxt->groupname || !ctxt->group) { + virKeyFileError(ctxt, VIR_ERR_CONF_SYNTAX, "value found before first group"); + return -1; + } + + keystart = ctxt->cur; + while (!IS_EOF&& c_isalnum(CUR)&& CUR != '=') + ctxt->cur++; + if (CUR != '=') { + virKeyFileError(ctxt, VIR_ERR_CONF_SYNTAX, "expected end of value name, expected '='"); + return -1; + } + + if (!(key = strndup(keystart, ctxt->cur - keystart))) { + virReportOOMError(); + return -1; + } + + NEXT; + valuestart = ctxt->cur; + while (!IS_EOF&& !IS_EOL(CUR)) + ctxt->cur++; + if (!(IS_EOF || IS_EOL(CUR))) { + virKeyFileError(ctxt, VIR_ERR_CONF_SYNTAX, "unexpected end of value"); + goto cleanup; + } + len = ctxt->cur - valuestart; + if (IS_EOF&& !IS_EOL(CUR)) + len++; + if (!(value = strndup(valuestart, len))) { + virReportOOMError(); + goto cleanup; + } + + if (virHashAddEntry(ctxt->group, key, value)< 0) + goto cleanup;
I meant here. Perhaps I commented at wrong place.
+ + NEXT; + + ret = 0; + +cleanup: + VIR_FREE(key);
Do we need to VIR_FREE(value) too?
No, the value is owned by the hash table now
How about virHashAddEntry fails? :-) Osier