Skip to content

Commit 8ea1e52

Browse files
nraynaudvisr
authored andcommitted
free the strings with the correct context handle
1 parent e92ab14 commit 8ea1e52

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

gen/generator.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ function rewrite(ex::Expr, cursor::Clang.CLFunctionDecl)
2626
if return_type_is_const_char(cursor)
2727
:(unsafe_string($cc))
2828
else
29-
:(string_copy_free($cc))
29+
if endswith(string(cname), "_r")
30+
:(string_copy_free($cc, handle))
31+
else
32+
:(string_copy_free($cc))
33+
end
3034
end
3135
else
3236
cc

src/LibGEOS.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ mutable struct GEOSContext
123123
end
124124

125125
"Get a copy of a string from GEOS, freeing the GEOS managed memory."
126-
function string_copy_free(s::Cstring, context::GEOSContext = _context)::String
126+
function string_copy_free(s::Cstring, context::Ptr{Cvoid} = _context.ptr)::String
127127
copy = unsafe_string(s)
128-
GEOSFree_r(context.ptr, pointer(s))
128+
GEOSFree_r(context, pointer(s))
129129
return copy
130130
end
131131

src/libgeos_api.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,8 @@ function GEOSRelate_r(handle, g1, g2)
12961296
g1::Ptr{GEOSGeometry},
12971297
g2::Ptr{GEOSGeometry},
12981298
)::Cstring
1299-
)
1299+
),
1300+
handle,
13001301
)
13011302
end
13021303

@@ -1317,7 +1318,8 @@ function GEOSRelateBoundaryNodeRule_r(handle, g1, g2, bnr)
13171318
g2::Ptr{GEOSGeometry},
13181319
bnr::Cint,
13191320
)::Cstring
1320-
)
1321+
),
1322+
handle,
13211323
)
13221324
end
13231325

@@ -1336,7 +1338,8 @@ function GEOSisValidReason_r(handle, g)
13361338
handle::GEOSContextHandle_t,
13371339
g::Ptr{GEOSGeometry},
13381340
)::Cstring
1339-
)
1341+
),
1342+
handle,
13401343
)
13411344
end
13421345

@@ -1414,7 +1417,8 @@ function GEOSGeomType_r(handle, g)
14141417
handle::GEOSContextHandle_t,
14151418
g::Ptr{GEOSGeometry},
14161419
)::Cstring
1417-
)
1420+
),
1421+
handle,
14181422
)
14191423
end
14201424

@@ -1834,7 +1838,8 @@ function GEOSWKTWriter_write_r(handle, writer, g)
18341838
writer::Ptr{GEOSWKTWriter},
18351839
g::Ptr{GEOSGeometry},
18361840
)::Cstring
1837-
)
1841+
),
1842+
handle,
18381843
)
18391844
end
18401845

@@ -2046,7 +2051,8 @@ function GEOSGeoJSONWriter_writeGeometry_r(handle, writer, g, indent)
20462051
g::Ptr{GEOSGeometry},
20472052
indent::Cint,
20482053
)::Cstring
2049-
)
2054+
),
2055+
handle,
20502056
)
20512057
end
20522058

@@ -3517,7 +3523,8 @@ function GEOSGeomToWKT_r(handle, g)
35173523
handle::GEOSContextHandle_t,
35183524
g::Ptr{GEOSGeometry},
35193525
)::Cstring
3520-
)
3526+
),
3527+
handle,
35213528
)
35223529
end
35233530

0 commit comments

Comments
 (0)