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

Commitd9c0c72

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 parentd63a172 commitd9c0c72

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
@@ -467,7 +467,7 @@ struct guts
467467
size_tnsub;/* copy of re_nsub */
468468
structsubre*tree;
469469
structcnfasearch;/* for fast preliminary search */
470-
intntree;/* number of subre's,less one */
470+
intntree;/* number of subre's,plus one */
471471
structcolormapcmap;
472472
intFUNCPTR(compare, (constchr*,constchr*,size_t));
473473
structsubre*lacons;/* lookahead-constraint vector */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp