From 42552e5efb98a417bc94ab7573c8f9dcbcb77deb Mon Sep 17 00:00:00 2001 From: wangqr Date: Sun, 9 Dec 2018 03:06:21 -0500 Subject: [PATCH] Correctly handle memory free using Lua GC Instead of manually free. Otherwise return value of `search' may refer to invalid memory. Fix Aegisub/Aegisub#99 --- automation/include/aegisub/re.moon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automation/include/aegisub/re.moon b/automation/include/aegisub/re.moon index 681786eb1..28b825da8 100644 --- a/automation/include/aegisub/re.moon +++ b/automation/include/aegisub/re.moon @@ -39,7 +39,7 @@ search = (re, str, start) -> res = regex.search re, str, str\len(), start return unless res != nil first, last = res[0], res[1] - ffi.C.free res + ffi.gc(res, ffi.C.free) first, last replace = (re, replacement, str, max_count) ->