summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2009-11-12 16:37:15 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2009-11-12 16:37:15 +0000
commitcc75a59dfff2dbe70a4896b77bae63a3617239de (patch)
treed7750db23a9dd50dac73322f6936da6d668648de
parentb9152dfa08f50e6b6793011744d88f1de2bed569 (diff)
fix memory leak found by parfait; ok jsg@
-rw-r--r--usr.bin/mg/line.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c
index 7c1b027dd4b..e8236277736 100644
--- a/usr.bin/mg/line.c
+++ b/usr.bin/mg/line.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: line.c,v 1.48 2009/06/05 18:02:06 kjell Exp $ */
+/* $OpenBSD: line.c,v 1.49 2009/11/12 16:37:14 millert Exp $ */
/* This file is in the public domain. */
@@ -423,19 +423,20 @@ ldelete(RSIZE n, int kflag)
int doto;
char *cp1, *cp2;
size_t len;
- char *sv;
+ char *sv = NULL;
int end;
int s;
+ int rval = FALSE;
if ((s = checkdirty(curbp)) != TRUE)
return (s);
if (curbp->b_flag & BFREADONLY) {
ewprintf("Buffer is read only");
- return (FALSE);
+ goto out;
}
len = n;
if ((sv = calloc(1, len + 1)) == NULL)
- return (FALSE);
+ goto out;
end = 0;
undo_add_delete(curwp->w_dotp, curwp->w_doto, n, (kflag & KREG));
@@ -445,7 +446,7 @@ ldelete(RSIZE n, int kflag)
doto = curwp->w_doto;
/* Hit the end of the buffer */
if (dotp == curbp->b_headp)
- return (FALSE);
+ goto out;
/* Size of the chunk */
chunk = dotp->l_used - doto;
@@ -454,10 +455,10 @@ ldelete(RSIZE n, int kflag)
/* End of line, merge */
if (chunk == 0) {
if (dotp == blastlp(curbp))
- return (FALSE);
+ goto out;
lchange(WFFULL);
if (ldelnewline() == FALSE)
- return (FALSE);
+ goto out;
end = strlcat(sv, "\n", len + 1);
--n;
continue;
@@ -489,9 +490,11 @@ ldelete(RSIZE n, int kflag)
n -= chunk;
}
if (kchunk(sv, (RSIZE)len, kflag) != TRUE)
- return (FALSE);
+ goto out;
+ rval = TRUE;
+out:
free(sv);
- return (TRUE);
+ return (rval);
}
/*