diff --git a/src/Amalgam/Amalgam.h b/src/Amalgam/Amalgam.h index a2cab244..5b5e5d0f 100644 --- a/src/Amalgam/Amalgam.h +++ b/src/Amalgam/Amalgam.h @@ -73,4 +73,7 @@ extern "C" AMALGAM_EXPORT bool IsSBFDataStoreEnabled(); AMALGAM_EXPORT size_t GetMaxNumThreads(); AMALGAM_EXPORT void SetMaxNumThreads(size_t max_num_threads); + + //for APIs that pass strings back, that memory needs to be cleaned up by the caller + AMALGAM_EXPORT void DeleteString(char *p); } diff --git a/src/Amalgam/AmalgamAPI.cpp b/src/Amalgam/AmalgamAPI.cpp index 1776c4b3..3180f22f 100644 --- a/src/Amalgam/AmalgamAPI.cpp +++ b/src/Amalgam/AmalgamAPI.cpp @@ -43,6 +43,11 @@ extern "C" // helper functions (not in API) // ************************************ + // WARNING: when using StringToCharPtr & StringToWCharPtr, ownership + // of the memory is returned to caller. When sending strings + // across the library boundary, the callers must free the + // memory using 'DeleteString', otherwise a leak occurs. + char* StringToCharPtr(std::string& value) { char* out = new char[value.length() + 1]; @@ -405,6 +410,11 @@ extern "C" return ct; } + void DeleteString(char *p) + { + delete[] p; + } + // ************************************ // Amalgam Engine Flags // ************************************