[libvirt] [PATCH 08/14] Add a virKeyfilePtr object for parsing '.ini' files

Daniel P. Berrange berrange at redhat.com
Fri Mar 23 12:16:13 UTC 2012


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 at 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;
> >+
> >+    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

Daniel 
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list