Browse Source

bindings: add a free_datastream handler function to avoid memleak on FFI

master
parent
commit
35532e7f65
Signed by: govanify GPG Key ID: DE62E1E2A6145556
2 changed files with 11 additions and 2 deletions
  1. +2
    -0
      bindings/c/c_ffi.cpp
  2. +9
    -2
      bindings/c/c_ffi.h

+ 2
- 0
bindings/c/c_ffi.cpp View File

@ -8,6 +8,8 @@ PCSX2Ipc *pcsx2ipc_new() { return new PCSX2Ipc(); }
void pcsx2ipc_initialize_batch(PCSX2Ipc *v) { return v->InitializeBatch(); }
void pcsx2ipc_free_datastream(char *data) { delete[] data; }
int pcsx2ipc_finalize_batch(PCSX2Ipc *v) {
auto p_batch = new PCSX2Ipc::BatchCommand;
auto batch = v->FinalizeBatch();


+ 9
- 2
bindings/c/c_ffi.h View File

@ -34,6 +34,13 @@ EXPORT_LIB PCSX2Ipc *pcsx2ipc_new();
*/
EXPORT_LIB void pcsx2ipc_initialize_batch(PCSX2Ipc *v);
/**
* This function frees datastream whose ownership was passed down to you. @n
* This is just a fancy wrapper around delete[] that is easier to use through
* FFI.
*/
EXPORT_LIB void pcsx2ipc_free_datastream(char *data);
/**
* In contrast to the C++ library this returns a handle to a struct. @n
* This requires you to free handles by yourself, see
@ -70,7 +77,7 @@ EXPORT_LIB char *pcsx2ipc_version(PCSX2Ipc *v, bool batch);
/**
* @see PCSX2Ipc::Status
*/
EXPORT_LIB PCSX2Ipc::EmuStatus pcsx2ipc_status(PCSX2Ipc* v, bool batch);
EXPORT_LIB PCSX2Ipc::EmuStatus pcsx2ipc_status(PCSX2Ipc *v, bool batch);
/**
* @see PCSX2Ipc::GetGameTitle
@ -90,7 +97,7 @@ EXPORT_LIB char *pcsx2ipc_getgameuuid(PCSX2Ipc *v, bool batch);
/**
* @see PCSX2Ipc::GetGameVersion
*/
EXPORT_LIB char* pcsx2ipc_getgameversion(PCSX2Ipc* v, bool batch);
EXPORT_LIB char *pcsx2ipc_getgameversion(PCSX2Ipc *v, bool batch);
/**
* @see PCSX2Ipc::SaveState


Loading…
Cancel
Save