Skip to content

Commit

Permalink
Fix potential memory leak with PyBuffer_release
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver committed Sep 22, 2023
1 parent 58d345d commit 56c0cbd
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/c/jpy_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,14 @@ PyObject* JPy_byte_buffer_internal(JNIEnv* jenv, PyObject* self, PyObject* args)

byteBufferRef = (*jenv)->NewDirectByteBuffer(jenv, pyBuffer->buf, pyBuffer->len);
if (byteBufferRef == NULL) {
PyBuffer_Release(pyBuffer);
PyMem_Free(pyBuffer);
return PyErr_NoMemory();
}

newPyObj = JObj_New(jenv, byteBufferRef);
if (newPyObj == NULL) {
PyBuffer_Release(pyBuffer);
PyMem_Free(pyBuffer);
return NULL;
}
Expand Down

0 comments on commit 56c0cbd

Please sign in to comment.