From d2d07100abec382c1163ec8ef16f1f16acb921b8 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Mon, 17 Oct 2016 22:58:43 -0400 Subject: [PATCH] Added a function to the C binding to free a char* pointer --- src/bindings/c/alpr_c.cpp | 9 ++++++++- src/bindings/c/alpr_c.h | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/bindings/c/alpr_c.cpp b/src/bindings/c/alpr_c.cpp index 4536a6a..cd207e5 100644 --- a/src/bindings/c/alpr_c.cpp +++ b/src/bindings/c/alpr_c.cpp @@ -21,7 +21,8 @@ #include #include #include - +#include + OPENALPRC_DLL_EXPORT OPENALPR* openalpr_init(const char* country, const char* configFile, const char* runtimeDir) { alpr::Alpr* alpr_inst = new alpr::Alpr(country, configFile, runtimeDir); @@ -99,6 +100,12 @@ OPENALPRC_DLL_EXPORT char* openalpr_recognize_encodedimage(OPENALPR* instance, u return result_obj; } + +OPENALPRC_DLL_EXPORT void openalpr_free_response_string(char* response) +{ + free(response); +} + OPENALPRC_DLL_EXPORT void openalpr_cleanup(OPENALPR* instance) { delete ((alpr::Alpr*) instance); diff --git a/src/bindings/c/alpr_c.h b/src/bindings/c/alpr_c.h index 0219732..5212886 100644 --- a/src/bindings/c/alpr_c.h +++ b/src/bindings/c/alpr_c.h @@ -65,6 +65,11 @@ char* openalpr_recognize_rawimage(OPENALPR* instance, unsigned char* pixelData, // Recognizes the encoded (e.g., JPEG, PNG) image. bytes are the raw bytes for the image data. char* openalpr_recognize_encodedimage(OPENALPR* instance, unsigned char* bytes, long long length, struct AlprCRegionOfInterest roi); +// Frees a char* response that was provided from a recognition request. +// This is required for interoperating with managed languages (e.g., C#) that can't free the memory themselves +void openalpr_free_response_string(char* response); + +// Free the memory for the OpenALPR instance created with openalpr_init void openalpr_cleanup(OPENALPR* instance);