From e55610e2bd919717817c61b273a974a48031882b Mon Sep 17 00:00:00 2001 From: Tom Yearke Date: Mon, 14 Apr 2014 12:04:13 -0400 Subject: [PATCH] python/pmapi.py - free C string using pointer from outAtom.cp instead of address from outAtom.vp (fixes possible seg fault) --- src/python/pcp/pmapi.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/python/pcp/pmapi.py b/src/python/pcp/pmapi.py index ff6922f..49dc583 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,10 +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) + python_char_array = outAtom.cp outAtom.cp = cast(python_char_array, c_char_p) # Free the C string LIBC.free(c_str) -- 1.8.4.2