From 7f857a511f84410631dea6590d4036c43170afc8 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 19 Mar 2014 11:09:24 -0400 Subject: [PATCH] Fix memory leak during regular expression execution. For a regex containing backrefs, pg_regexec() might fail to free all the sub-DFAs that were created during execution, resulting in a permanent (session lifespan) memory leak. Problem was introduced by me in commit 587359479acbbdc95c8e37da40707e37097423f5. Per report from Sandro Santilli; diagnosis by Greg Stark. --- src/backend/regex/regexec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/regex/regexec.c b/src/backend/regex/regexec.c index 0edb83c109..2e976627f5 100644 --- a/src/backend/regex/regexec.c +++ b/src/backend/regex/regexec.c @@ -259,6 +259,7 @@ pg_regexec(regex_t *re, /* clean up */ if (v->pmatch != pmatch && v->pmatch != mat) FREE(v->pmatch); + n = (size_t) v->g->ntree; for (i = 0; i < n; i++) { if (v->subdfas[i] != NULL) -- 2.40.0