Skip to content

topdown/regex.go cache leaks #9087

Description

@charlesdaniels

Short description

There is a cache for compiled regexes here. getRegexp() does clean up the cache here if it has gone over size by removing up to 1 cache entry. However, getRegexpTemplate() inserts into the cache here but elides the size guard.

As a result, repeated calls to builtinRegexMatchTemplate() cause the regex cache to grow without bound, and even if builtinRegexMatch() or other builtins are called which do clear the cache, they'll only reduce it by 1 entry.

Steps To Reproduce

No specified steps. Claude brought it up in a code review for something else, I stared at it with my human eyeballs and it seems to check out.

Expected behavior

Caches should be be bounded in size.

Additional context

I'm open to writing a PR for this. It should be an easy fix. I'd tackle it by just writing a helper function to interact with the cache and moving all the cache management logic into it, then using the helper everywhere. Should be a small PR. Want to make sure the patch was wanted before I do the work though.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions