Skip to content

Commit ef1d1a9

Browse files
committed
Check malloc and realloc for memory errors.
1 parent 57c19ca commit ef1d1a9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/UDF.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function stepfunc(init, func, fsym=symbol(string(func)*"_step"))
8989
valsize = 256
9090
# avoid the garbage collector using malloc
9191
valptr = convert(Ptr{UInt8}, c_malloc(valsize))
92+
valptr == C_NULL && throw(SQLiteException("memory error"))
9293
else
9394
# size of serialized value is first sizeof(Int) bytes
9495
valsize = bytestoint(acptr, 1, intsize)
@@ -113,7 +114,13 @@ function stepfunc(init, func, fsym=symbol(string(func)*"_step"))
113114
newsize = sizeof(funcret)
114115
if newsize > valsize
115116
# TODO: increase this in a cleverer way?
116-
valptr = convert(Ptr{UInt8}, c_realloc(valptr, newsize))
117+
tmp = convert(Ptr{UInt8}, c_realloc(valptr, newsize))
118+
if tmp == C_NULL
119+
c_free(valptr)
120+
throw(SQLiteException("memory error"))
121+
else
122+
valptr = tmp
123+
end
117124
end
118125
# copy serialized return value
119126
unsafe_copy!(valptr, pointer(funcret), newsize)

0 commit comments

Comments
 (0)