# Using Cxx malloc error: pointer being freed was not allocated

**URL:** <https://discourse.julialang.org/t/using-cxx-malloc-error-pointer-being-freed-was-not-allocated/12198>\
**Category:** New to Julia\
**Tags:** question, cxx\
**Created:** [July 5, 2018, 10:40pm UTC](https://discourse.julialang.org/t/using-cxx-malloc-error-pointer-being-freed-was-not-allocated/12198 "2018-07-05T22:40:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avary\_Kolasinski](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Avary\_Kolasinski](https://discourse.julialang.org/u/Avary_Kolasinski)\
**Post date:** [July 5, 2018, 10:40pm UTC](https://discourse.julialang.org/t/using-cxx-malloc-error-pointer-being-freed-was-not-allocated/12198/1 "2018-07-05T22:40:15Z")

</div>

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!
