Skip to content

Commit

Permalink
Use regfree after we're done with preg.
Browse files Browse the repository at this point in the history
From gilles@
  • Loading branch information
martijn committed Dec 23, 2020
1 parent ecf4b81 commit 79a034b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions usr.sbin/smtpd/table.c
@@ -1,4 +1,4 @@
/* $OpenBSD: table.c,v 1.48 2019/01/10 07:40:52 eric Exp $ */
/* $OpenBSD: table.c,v 1.49 2020/12/23 08:12:14 martijn Exp $ */

/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
Expand Down Expand Up @@ -464,6 +464,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;
Expand All @@ -473,7 +474,11 @@ table_regex_match(const char *string, const char *pattern)
if (regcomp(&preg, pattern, cflags) != 0)
return (0);

if (regexec(&preg, string, 0, NULL, 0) != 0)
ret = regexec(&preg, string, 0, NULL, 0);

regfree(&preg);

if (ret != 0)
return (0);

return (1);
Expand Down

0 comments on commit 79a034b

Please sign in to comment.