zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: Fix leak during Y shortcircuit glob qualifier
Date: Wed, 23 Sep 2015 23:54:50 +0200	[thread overview]
Message-ID: <1443045290-26615-1-git-send-email-mikachu@gmail.com> (raw)

The closedir(lock) is the leak I actually did see in usage, I have no
idea if the other part is needed/harmful though. I'll commit just the
closedir if nobody has any opinions.

---
 Src/glob.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/Src/glob.c b/Src/glob.c
index 4db6570..8fbefc9 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -534,7 +534,7 @@ scanner(Complist q, int shortcircuit)
 		    if (!closure || !statfullpath("", NULL, 1)) {
 			scanner((q->closure) ? q : q->next, shortcircuit);
 			if (shortcircuit && shortcircuit == matchct)
-			    return;
+			    goto freedir;
 		    }
 		    pathbuf[pathpos = oppos] = '\0';
 		}
@@ -544,7 +544,7 @@ scanner(Complist q, int shortcircuit)
 		str = dupstrpfx(str, l);
 	    insert(str, 0);
 	    if (shortcircuit && shortcircuit == matchct)
-		return;
+		goto freedir;
 	}
     } else {
 	/* Do pattern matching on current path section. */
@@ -635,8 +635,10 @@ scanner(Complist q, int shortcircuit)
 		} else {
 		    /* if the last filename component, just add it */
 		    insert(fn, 1);
-		    if (shortcircuit && shortcircuit == matchct)
-			return;
+		    if (shortcircuit && shortcircuit == matchct) {
+			closedir(lock);
+			goto freedir;
+		    }
 		}
 	    }
 	}
@@ -659,6 +661,7 @@ scanner(Complist q, int shortcircuit)
 	    hrealloc(subdirs, subdirlen, 0);
 	}
     }
+freedir:
     if (pbcwdsav < pathbufcwd) {
 	if (restoredir(&ds))
 	    zerr("current directory lost during glob");
-- 
2.5.0


             reply	other threads:[~2015-09-23 21:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-23 21:54 Mikael Magnusson [this message]
2015-09-24  3:12 ` Bart Schaefer
2015-09-24  3:38   ` Mikael Magnusson
2015-09-24  5:18     ` Bart Schaefer
2015-09-24 18:55       ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443045290-26615-1-git-send-email-mikachu@gmail.com \
    --to=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).