Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/mdocml/dist CID 1288947: Prevent fd leak.



details:   https://anonhg.NetBSD.org/src/rev/606ad8c08926
branches:  trunk
changeset: 342751:606ad8c08926
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 07 19:49:25 2016 +0000

description:
CID 1288947: Prevent fd leak.

diffstat:

 external/bsd/mdocml/dist/read.c |  9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diffs (38 lines):

diff -r fce0e40ebaae -r 606ad8c08926 external/bsd/mdocml/dist/read.c
--- a/external/bsd/mdocml/dist/read.c   Thu Jan 07 19:46:00 2016 +0000
+++ b/external/bsd/mdocml/dist/read.c   Thu Jan 07 19:49:25 2016 +0000
@@ -1,4 +1,4 @@
-/*     $Id: read.c,v 1.12 2015/12/18 14:30:41 christos Exp $ */
+/*     $Id: read.c,v 1.13 2016/01/07 19:49:25 christos Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps%bsd.lv@localhost>
  * Copyright (c) 2010-2015 Ingo Schwarze <schwarze%openbsd.org@localhost>
@@ -336,6 +336,7 @@
 
        lnn = curp->line;
        pos = 0;
+       fd = -1;
 
        while (i < blk.sz) {
                if (0 == pos && '\0' == blk.buf[i])
@@ -530,8 +531,7 @@
                        if ( ! (curp->options & MPARSE_SO) &&
                            (i >= blk.sz || blk.buf[i] == '\0')) {
                                curp->sodest = mandoc_strdup(ln.buf + of);
-                               free(ln.buf);
-                               return;
+                               goto out;
                        }
                        /*
                         * We remove `so' clauses from our lookaside
@@ -611,7 +611,10 @@
                pos = 0;
        }
 
+out:
        free(ln.buf);
+       if (fd != -1)
+               close(fd);
 }
 
 static int



Home | Main Index | Thread Index | Old Index