Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid free call in interpreted mode #12496

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/regex.cr
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,19 @@ class Regex
raise ArgumentError.new("#{String.new(errptr)} at #{erroffset}") if @re.null?
@extra = LibPCRE.study(@re, LibPCRE::STUDY_JIT_COMPILE, out studyerrptr)
if @extra.null? && studyerrptr
LibPCRE.free.call @re.as(Void*)
{% unless flag?(:interpreted) %}
LibPCRE.free.call @re.as(Void*)
{% end %}
raise ArgumentError.new("#{String.new(studyerrptr)}")
end
LibPCRE.full_info(@re, nil, LibPCRE::INFO_CAPTURECOUNT, out @captures)
end

def finalize
LibPCRE.free_study @extra
LibPCRE.free.call @re.as(Void*)
{% unless flag?(:interpreted) %}
LibPCRE.free.call @re.as(Void*)
{% end %}
end

# Determines Regex's source validity. If it is, `nil` is returned.
Expand All @@ -283,7 +287,9 @@ class Regex
def self.error?(source) : String?
re = LibPCRE.compile(source, (Options::UTF_8 | Options::NO_UTF8_CHECK | Options::DUPNAMES), out errptr, out erroffset, nil)
if re
LibPCRE.free.call re.as(Void*)
{% unless flag?(:interpreted) %}
LibPCRE.free.call re.as(Void*)
{% end %}
nil
else
"#{String.new(errptr)} at #{erroffset}"
Expand Down