Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7d896a

Browse files
committed
Fix low-probability memory leak in regex execution.
After an internal failure in shortest() or longest() while pinning down theexact location of a match, find() forgot to free the DFA structure beforereturning. This is pretty unlikely to occur, since we just successfullyran the "search" variant of the DFA; but it could happen, and it wouldresult 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 themeaning of the "ntree" field.I happened across these issues while comparing our code to Tcl's versionof the library.
1 parent5ed2d2c commitf7d896a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

‎src/backend/regex/regcomp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct vars
228228
structsubre*tree;/* subexpression tree */
229229
structsubre*treechain;/* all tree nodes allocated */
230230
structsubre*treefree;/* any free tree nodes */
231-
intntree;/* number of tree nodes */
231+
intntree;/* number of tree nodes, plus one */
232232
structcvec*cv;/* interface cvec */
233233
structcvec*cv2;/* utility cvec */
234234
structsubre*lacons;/* lookahead-constraint vector */

‎src/backend/regex/regexec.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,11 @@ find(struct vars * v,
348348
(chr**)NULL,&hitend);
349349
else
350350
end=longest(v,d,begin,v->stop,&hitend);
351-
NOERR();
351+
if (ISERR())
352+
{
353+
freedfa(d);
354+
returnv->err;
355+
}
352356
if (hitend&&cold==NULL)
353357
cold=begin;
354358
if (end!=NULL)

‎src/include/regex/regguts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ struct guts
465465
size_tnsub;/* copy of re_nsub */
466466
structsubre*tree;
467467
structcnfasearch;/* for fast preliminary search */
468-
intntree;/* number of subre's,less one */
468+
intntree;/* number of subre's,plus one */
469469
structcolormapcmap;
470470
intFUNCPTR(compare, (constchr*,constchr*,size_t));
471471
structsubre*lacons;/* lookahead-constraint vector */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp