Skip to content

Commit 6623aca

Browse files
committed
Do not free CStringWrapper if not native
1 parent a578c04 commit 6623aca

File tree

1 file changed

+13
-4
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi

1 file changed

+13
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyMethodDefHelper.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Object allocate() {
156156
CStructAccess.WriteIntNode writeIntNode = CStructAccessFactory.WriteIntNodeGen.getUncached();
157157

158158
assert name != null;
159-
Object nameWrapper;
159+
CStringWrapper nameWrapper;
160160
try {
161161
nameWrapper = new CStringWrapper(name);
162162
} catch (CannotCastException e) {
@@ -217,9 +217,18 @@ static void free(Object pointer) {
217217
}
218218
LOGGER.finer(String.format("PyMethodDef(%s, %s, %d, %s) at %s freed.", name, meth, flags, doc, PythonUtils.formatPointer(pointer)));
219219
}
220-
FreeNode.executeUncached(namePointer);
221-
if (PGuards.isNullOrZero(namePointer, InteropLibrary.getUncached())) {
222-
FreeNode.executeUncached(docPointer);
220+
// managed case: 'const char *' is represented by CStringWrapper
221+
if (namePointer instanceof CStringWrapper nameWrapper) {
222+
nameWrapper.free();
223+
} else {
224+
FreeNode.executeUncached(namePointer);
225+
}
226+
if (docPointer instanceof CStringWrapper docWrapper) {
227+
docWrapper.free();
228+
} else {
229+
if (PGuards.isNullOrZero(docPointer, InteropLibrary.getUncached())) {
230+
FreeNode.executeUncached(docPointer);
231+
}
223232
}
224233
FreeNode.executeUncached(pointer);
225234
}

0 commit comments

Comments
 (0)