Skip to content

Commit ba9eb29

Browse files
committed
Fix low-probability memory leak in regex execution.
After an internal failure in shortest() or longest() while pinning down the exact location of a match, find() forgot to free the DFA structure before returning. This is pretty unlikely to occur, since we just successfully ran the "search" variant of the DFA; but it could happen, and it would result in a session-lifespan memory leak since this code uses malloc() directly. Problem seems to have been aboriginal in Spencer's library, so back-patch all the way. In passing, correct a thinko in a comment I added awhile back about the meaning of the "ntree" field. I happened across these issues while comparing our code to Tcl's version of the library.
1 parent f7eeb32 commit ba9eb29

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/backend/regex/regexec.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ find(struct vars * v,
323323
(chr **) NULL, &hitend);
324324
else
325325
end = longest(v, d, begin, v->stop, &hitend);
326-
NOERR();
326+
if (ISERR())
327+
{
328+
freedfa(d);
329+
return v->err;
330+
}
327331
if (hitend && cold == NULL)
328332
cold = begin;
329333
if (end != NULL)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy