From 9d14cc4234e100ba14606d30975508934f069255 Mon Sep 17 00:00:00 2001 From: Tom Yearke Date: Wed, 26 Mar 2014 15:44:26 -0400 Subject: [PATCH] python/pmapi - simplify memory management for users in pmExtractValue --- src/python/pcp/pmapi.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/python/pcp/pmapi.py b/src/python/pcp/pmapi.py index fd67a9e..18d136e 100644 --- a/src/python/pcp/pmapi.py +++ b/src/python/pcp/pmapi.py @@ -1333,6 +1333,12 @@ class pmContext(object): byref(outAtom), outtype) if status < 0: raise pmErr, status + # If value was allocated in C memory, copy to Python memory and free C. + if outtype == c_api.PM_TYPE_STRING: + c_char_pointer_address = outAtom.vp + python_char_array = create_string_buffer(outAtom.cp) + outAtom.cp = cast(python_char_array, c_char_p) + LIBC.free(c_char_pointer_address) return outAtom @staticmethod -- 1.8.4.2