# Pointer being freed was not allocated

**URL:** <https://discourse.julialang.org/t/pointer-being-freed-was-not-allocated/3131>\
**Category:** General Usage\
**Created:** [April 9, 2017, 9:29pm UTC](https://discourse.julialang.org/t/pointer-being-freed-was-not-allocated/3131 "2017-04-09T21:29:35Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [April 12, 2017, 4:36pm UTC](https://discourse.julialang.org/t/pointer-being-freed-was-not-allocated/3131/8 "2017-04-12T16:36:44Z")

</div>

Thank you all for your answers.

Hopefully, I won’t have to change the C-library. As suggested, a solution might be to do all allocations on C-side.

@ihnorton Here is a copy from [these examples](https://github.com/rveltz/LSODA.jl/issues/15) which generates the malloc issue.

```julia
using LSODA

function rhs!(t, x, ydot, data)
	ydot[1]=1.0E4 * x[2] * x[3] - .04E0 * x[1]
	ydot[3]=3.0E7 * x[2] * x[2]
	ydot[2]=-ydot[1] - ydot[3]
  nothing
end

rhs!(t, x, ydot) = rhs!(t, x, ydot, nothing)

y0 = [1.,0.,0.]
# case with a vector
println("\n####################################\n--> Use of a vector of times where output is required")
tspan = [4.*10.0^k for k=-1:10]
ctx, res = @time LSODA.lsoda(rhs!, y0, tspan, reltol= 1e-4,abstol = Vector([1.e-6,1.e-10,1.e-6]))
lsoda_free(ctx)

```

returns

```julia
unhandled error message: 
julia(21398,0x7fff7860e000) malloc: *** error for object 0x110698dd0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

signal (6): Abort trap: 6
while loading /Users/rveltz/Downloads/crash-lsoda.jl, in expression starting on line 18
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 2748719 (Pool: 2747721; Big: 998); GC: 2

```

where L18 refers to `lsoda_free(ctx)` so somehow my function `lsoda_free` is buggy.

---

_[View the full topic](https://discourse.julialang.org/t/pointer-being-freed-was-not-allocated/3131)._
