[libvirt] [PATCH 3/5] build: prohibit raw malloc and free
Jiri Denemark
jdenemar at redhat.com
Fri Feb 3 09:03:48 UTC 2012
On Thu, Feb 02, 2012 at 17:33:22 -0700, Eric Blake wrote:
> Our HACKING discourages use of malloc and free, for at least
> a couple of years now. But we weren't enforcing it, until now :)
>
> For now, I've exempted python and tests, and will clean those up
> in subsequent patches. Examples should be permanently exempt,
> since anyone copying our examples won't have use of our
> internal-only memory.h via libvirt_util.la.
>
> * cfg.mk (sc_prohibit_raw_allocation): New rule.
> (exclude_file_name_regexp--sc_prohibit_raw_allocation): and
> exemptions.
> * src/cpu/cpu.c (cpuDataFree): Avoid false positive.
> * src/conf/network_conf.c (virNetworkDNSSrvDefParseXML): Fix
> offenders.
> * src/libxl/libxl_conf.c (libxlMakeDomBuildInfo, libxlMakeVfb)
> (libxlMakeDeviceModelInfo): Likewise.
> * src/rpc/virnetmessage.c (virNetMessageSaveError): Likewise.
> * tools/virsh.c (_vshMalloc, _vshCalloc): Likewise.
> ---
> cfg.mk | 9 +++++++++
> src/conf/network_conf.c | 2 +-
> src/cpu/cpu.c | 4 ++--
> src/libxl/libxl_conf.c | 13 +++++++------
> src/rpc/virnetmessage.c | 23 ++++++++++++-----------
> tools/virsh.c | 9 +++++----
> 6 files changed, 36 insertions(+), 24 deletions(-)
>
> diff --git a/cfg.mk b/cfg.mk
> index c13db18..f91c90c 100644
> --- a/cfg.mk
> +++ b/cfg.mk
> @@ -316,6 +316,12 @@ sc_prohibit_internal_functions:
> halt='use VIR_ macros instead of internal functions' \
> $(_sc_search_regexp)
>
> +# Avoid raw malloc and free, except in documentation comments.
> +sc_prohibit_raw_allocation:
> + @prohibit='^.[^*].*\<((m|c|re)alloc|free) *\([^)]' \
> + halt='use VIR_ macros from memory.h instead of malloc/free' \
> + $(_sc_search_regexp)
> +
> # Avoid functions that can lead to double-close bugs.
> sc_prohibit_close:
> @prohibit='([^>.]|^)\<[fp]?close *\(' \
> @@ -737,6 +743,9 @@ exclude_file_name_regexp--sc_prohibit_newline_at_end_of_diagnostic = \
> exclude_file_name_regexp--sc_prohibit_nonreentrant = \
> ^((po|tests)/|docs/.*py$$|tools/(virsh|console)\.c$$)
>
> +exclude_file_name_regexp--sc_prohibit_raw_allocation = \
> + ^(src/util/memory\.[ch]|(examples|python|tests)/.*)$$
> +
> exclude_file_name_regexp--sc_prohibit_readlink = ^src/util/util\.c$$
>
> exclude_file_name_regexp--sc_prohibit_setuid = ^src/util/util\.c$$
...
> diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
> index 1f39934..01c31bb 100644
> --- a/src/cpu/cpu.c
> +++ b/src/cpu/cpu.c
> @@ -1,7 +1,7 @@
> /*
> * cpu.c: internal functions for CPU manipulation
> *
> - * Copyright (C) 2009-2011 Red Hat, Inc.
> + * Copyright (C) 2009-2012 Red Hat, Inc.
> *
> * This library is free software; you can redistribute it and/or
> * modify it under the terms of the GNU Lesser General Public
> @@ -220,7 +220,7 @@ cpuDataFree(const char *arch,
> return;
> }
>
> - driver->free(data);
> + (driver->free)(data);
> }
I was wondering why you changed this but then I realized it's just to shut up
your new syntax-check rule. Nice.
ACK
Jirka
More information about the libvir-list
mailing list