Using Cxx malloc error: pointer being freed was not allocated

Hello,

I am calling a C++ function in my Julia function using Cxx. Within the C++ function I use:
buffer = malloc(size)

free(buffer);
so the buffer is not passing into the Julia function however, when running the Julia function I am getting the following error:
julia(77299,0x7fff9e46b380) malloc: *** error for object 0x7ff4b9e86b20: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Is this error due to the malloc function in the C++ code or is it something else?

Any insight into how to fix this issue would be great.
Thank you!