Python. NULL a pointer returned from a c funtion.
by jmgibson1981 from LinuxQuestions.org on (#6HWBQ)
I figured out to use the gc library. But I'm still getting a single leak which is only 120bytes. I'm thinking it's the pointer not being NULLed.
How can I do that? Once I've run del var it's got nothing to point to.
That or am I going about this wrong. stuck.
Code:#!/usr/bin/python3
# python bindings for libjmgeneral.so
import ctypes
from ctypes import *
import pathlib
import gc
lib = pathlib.Path().absolute() / "/usr/local/lib/libjmgeneral.so"
libjmgen_lib = ctypes.CDLL(lib)
def random_gen(a, b):
return libjmgen_lib.random_gen(a, b)
def clear_ptr(a):
del a
def prompt_input_getline(a):
prompt_input_getline = libjmgen_lib.prompt_input_getline
prompt_input_getline.argtypes = [c_char_p]
prompt_input_getline.restype = c_char_p
result = prompt_input_getline(a.encode('utf-8'))
return result.decode('utf-8')
y = prompt_input_getline("lol")
print(y)
clear_ptr(y)
How can I do that? Once I've run del var it's got nothing to point to.
That or am I going about this wrong. stuck.
Code:#!/usr/bin/python3
# python bindings for libjmgeneral.so
import ctypes
from ctypes import *
import pathlib
import gc
lib = pathlib.Path().absolute() / "/usr/local/lib/libjmgeneral.so"
libjmgen_lib = ctypes.CDLL(lib)
def random_gen(a, b):
return libjmgen_lib.random_gen(a, b)
def clear_ptr(a):
del a
def prompt_input_getline(a):
prompt_input_getline = libjmgen_lib.prompt_input_getline
prompt_input_getline.argtypes = [c_char_p]
prompt_input_getline.restype = c_char_p
result = prompt_input_getline(a.encode('utf-8'))
return result.decode('utf-8')
y = prompt_input_getline("lol")
print(y)
clear_ptr(y)