]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: forbid freeing const pointers
authorEric Blake <eblake@redhat.com>
Tue, 15 Jul 2014 19:44:26 +0000 (13:44 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 16 Jul 2014 12:48:53 +0000 (06:48 -0600)
commita0b5ace28c78c6afa9f37665cdb41caa778a229f
tree5512d1e640db88a398c69d6e0a052f3a6601a425
parent0b0c641b668bd46f9678861eb4c776d03e541b97
util: forbid freeing const pointers

Now that we've finally fixed all the violators, it's time to
enforce that any pointer to a const object is never freed (it
is aliasing some other memory, where the non-const original
should be freed instead).  Alas, the code still needs a normal
vs. Coverity version, but at least we are still guaranteeing
that the macro call evaluates its argument exactly once.

I verified that we still get the following compiler warnings,
which in turn halts the build thanks to -Werror on gcc (hmm,
gcc 4.8.3's placement of the ^ for ?: type mismatch is a bit
off, but that's not our problem):

    int oops1 = 0;
    VIR_FREE(oops1);
    const char *oops2 = NULL;
    VIR_FREE(oops2);
    struct blah { int dummy; } oops3;
    VIR_FREE(oops3);

util/virauthconfig.c:159:35: error: pointer/integer type mismatch in conditional expression [-Werror]
     VIR_FREE(oops1);
                                   ^
util/virauthconfig.c:161:5: error: passing argument 1 of 'virFree' discards 'const' qualifier from pointer target type [-Werror]
     VIR_FREE(oops2);
     ^
In file included from util/virauthconfig.c:28:0:
util/viralloc.h:79:6: note: expected 'void *' but argument is of type 'const void *'
 void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1);
      ^
util/virauthconfig.c:163:35: error: type mismatch in conditional expression
     VIR_FREE(oops3);
                                   ^

* src/util/viralloc.h (VIR_FREE): No longer cast away const.
* src/xenapi/xenapi_utils.c (xenSessionFree): Work around bogus
header.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/util/viralloc.h
src/xenapi/xenapi_utils.c