LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Free memory after using GetRS232ErrorString() to avoid memory leak?

Hello, Is it necessary to free memory after using function GetRS232ErrorString() to avoid memory leak? Example 1: int main(); { char *strError=NULL; strError = GetRS232ErrorString(55); /* just an example for error message */ free(strError ); /* Do I need to free this pointer? */ } Example 2: int main(); { MessagePopup ("Error", GetRS232ErrorString(55)); ; /* Will I get a memory leak with this function call? */ } BR Frank
0 Kudos
Message 1 of 2
(2,856 Views)

It's a pity that the documentation is indeed so poor in this case, but testing shows that it always returns the same pointer, no matter the error code, so it seems to be using an internal buffer and you are not supposed to free the string (but need to copy it before the next call to GetRS232ErrorString if you need to keep the text). It does however return a different pointer for every thread, so atl least it seems to be thread safe.

 

Cheers, Marcel 

Message 2 of 2
(2,836 Views)