From 77446a59e33b0c4be2ca8043feefc157842f1607 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 2 Feb 2012 15:45:54 -0700 Subject: python: use libvirt_util to avoid raw free This patch starts the process of elevating the python binding code to be on the same level as the rest of libvirt when it comes to requiring good coding styles. Statically linking against the libvirt_util library makes it much easier to write good code, rather than having to open-code and reinvent things locally. Done by global search and replace of s/free(/VIR_FREE(/, followed by hand-inspection of remaining malloc and redundant memset. * cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation): Remove python from exemption. * python/Makefile.am (INCLUDES): Add gnulib and src/util. Drop $(top_builddir)/$(subdir), as automake already guarantees that. (mylibs, myqemulibs): Pull in libvirt_util and gnulib. (libvirtmod_la_CFLAGS): Catch compiler warnings if configured to use -Werror. * python/typewrappers.c (libvirt_charPtrSizeWrap) (libvirt_charPtrWrap): Convert free to VIR_FREE. * python/generator.py (print_function_wrapper): Likewise. * python/libvirt-override.c: Likewise. --- typewrappers.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'typewrappers.c') diff --git a/typewrappers.c b/typewrappers.c index 9021ce3..3f200b3 100644 --- a/typewrappers.c +++ b/typewrappers.c @@ -2,7 +2,7 @@ * types.c: converter functions between the internal representation * and the Python objects * - * Copyright (C) 2005, 2007 Red Hat, Inc. + * Copyright (C) 2005, 2007, 2012 Red Hat, Inc. * * Daniel Veillard */ @@ -16,6 +16,8 @@ #include "typewrappers.h" +#include "memory.h" + #ifndef Py_CAPSULE_H typedef void(*PyCapsule_Destructor)(void *, void *); #endif @@ -86,7 +88,7 @@ libvirt_charPtrSizeWrap(char *str, Py_ssize_t size) return (Py_None); } ret = PyString_FromStringAndSize(str, size); - free(str); + VIR_FREE(str); return (ret); } @@ -100,7 +102,7 @@ libvirt_charPtrWrap(char *str) return (Py_None); } ret = PyString_FromString(str); - free(str); + VIR_FREE(str); return (ret); } -- cgit