[diff] src/usr.sbin/smtpd: plug a memory leak in regex lookups

2020-12-23 Thread Gilles CHEHADE
Hello,

The following diff plugs a memory leak in regex lookups.

Cheers,


diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c
index 4691..d1578403 100644
--- a/usr.sbin/smtpd/table.c
+++ b/usr.sbin/smtpd/table.c
@@ -470,6 +470,7 @@ table_regex_match(const char *string, const char *pattern)
 {
regex_t preg;
int cflags = REG_EXTENDED|REG_NOSUB;
+   int ret;
 
if (strncmp(pattern, "(?i)", 4) == 0) {
cflags |= REG_ICASE;
@@ -479,7 +480,11 @@ table_regex_match(const char *string, const char *pattern)
if (regcomp(, pattern, cflags) != 0)
return (0);
 
-   if (regexec(, string, 0, NULL, 0) != 0)
+   ret = regexec(, string, 0, NULL, 0);
+
+   regfree();
+
+   if (ret != 0)
return (0);
 
return (1);



Re: [diff] src/usr.sbin/smtpd: plug a memory leak in regex lookups

2020-12-23 Thread Martijn van Duren
Committed, thanks.

On Wed, 2020-12-23 at 08:54 +0100, Gilles CHEHADE wrote:
> Hello,
> 
> The following diff plugs a memory leak in regex lookups.
> 
> Cheers,
> 
> 
> diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c
> index 4691..d1578403 100644
> --- a/usr.sbin/smtpd/table.c
> +++ b/usr.sbin/smtpd/table.c
> @@ -470,6 +470,7 @@ table_regex_match(const char *string, const char *pattern)
>  {
> regex_t preg;
> int cflags = REG_EXTENDED|REG_NOSUB;
> +   int ret;
>  
> if (strncmp(pattern, "(?i)", 4) == 0) {
> cflags |= REG_ICASE;
> @@ -479,7 +480,11 @@ table_regex_match(const char *string, const char 
> *pattern)
> if (regcomp(, pattern, cflags) != 0)
> return (0);
>  
> -   if (regexec(, string, 0, NULL, 0) != 0)
> +   ret = regexec(, string, 0, NULL, 0);
> +
> +   regfree();
> +
> +   if (ret != 0)
> return (0);
>  
> return (1);
>