>From 7e8c4f12352929cf93346237112b1e9542e13bff Mon Sep 17 00:00:00 2001 From: Tom Yearke Date: Mon, 14 Apr 2014 14:49:45 -0400 Subject: [PATCH] python/pmapi.py - free C string using pointer from outAtom.cp instead of address from outAtom.vp (fixes possible seg fault), resolve valgrind read errors --- src/python/pcp/pmapi.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/python/pcp/pmapi.py b/src/python/pcp/pmapi.py index ff6922f..9b2c04a 100644 --- a/src/python/pcp/pmapi.py +++ b/src/python/pcp/pmapi.py @@ -81,7 +81,7 @@ from ctypes import c_char, c_int, c_uint, c_long, c_char_p, c_void_p from ctypes import c_longlong, c_ulonglong, c_float, c_double from ctypes import CDLL, POINTER, CFUNCTYPE, Structure, Union from ctypes import addressof, pointer, sizeof, cast, byref -from ctypes import create_string_buffer +from ctypes import create_string_buffer, memmove from ctypes.util import find_library ############################################################################## @@ -1663,11 +1663,12 @@ class pmContext(object): raise pmErr, status if outtype == c_api.PM_TYPE_STRING: - # Get address of C string - c_str = outAtom.vp + # Get pointer to C string + c_str = c_char_p() + memmove(byref(c_str), addressof(outAtom) + pmAtomValue.cp.offset, + sizeof(c_char_p)) # Convert to a python string and have result point to it - python_char_array = ctypes.string_at(c_str) - outAtom.cp = cast(python_char_array, c_char_p) + outAtom.cp = outAtom.cp # Free the C string LIBC.free(c_str) return outAtom -- 1.8.4.2