[hackers] [sent] Fix memory leak and print a warning on invalid regex || FRIGN

From: <git_AT_suckless.org>
Date: Fri, 12 Aug 2016 10:03:21 +0200 (CEST)

commit 072a318adbdf091a58587c740d081d0ccfff271c
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Thu Aug 11 21:30:34 2016 +0200
Commit: Markus Teich <markus.teich_AT_stusta.mhn.de>
CommitDate: Thu Aug 11 23:42:09 2016 +0200

    Fix memory leak and print a warning on invalid regex
    
    This will minimize the already low memory usage of sent.

diff --git a/sent.c b/sent.c
index a4d0cd2..1e1353c 100644
--- a/sent.c
+++ b/sent.c
_AT_@ -185,12 +185,16 @@ ffload(Slide *s)
 
         for (i = 0; i < LEN(filters); i++) {
                 if (regcomp(&regex, filters[i].regex,
- REG_NOSUB | REG_EXTENDED | REG_ICASE))
+ REG_NOSUB | REG_EXTENDED | REG_ICASE)) {
+ fprintf(stderr, "sent: Invalid regex '%s'\n", filters[i].regex);
                         continue;
+ }
                 if (!regexec(&regex, filename, 0, NULL, 0)) {
                         bin = filters[i].bin;
+ regfree(&regex);
                         break;
                 }
+ regfree(&regex);
         }
         if (!bin)
                 die("sent: Unable to find matching filter for file %s", filename);
Received on Fri Aug 12 2016 - 10:03:21 CEST

This archive was generated by hypermail 2.3.0 : Fri Aug 12 2016 - 10:12:18 CEST