Skip to content

Commit

Permalink
19317: Adds DeleteString to API for cleaning up strings passed to u…
Browse files Browse the repository at this point in the history
…ser, MINOR (#77)
  • Loading branch information
calebwherry authored Feb 20, 2024
1 parent b9ded71 commit d196860
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Amalgam/Amalgam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 10 additions & 0 deletions src/Amalgam/AmalgamAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -405,6 +410,11 @@ extern "C"
return ct;
}

void DeleteString(char *p)
{
delete[] p;
}

// ************************************
// Amalgam Engine Flags
// ************************************
Expand Down

0 comments on commit d196860

Please sign in to comment.