summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2012-10-26 20:46:13 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2012-10-26 20:46:13 +0000
commit5d26c2a62ef5a021ff14d9c55693b39494397394 (patch)
treef22f17179e9fb1a0fb8768f9bd716a78d5bcf52a /usr.bin/mg
parentde60ac72edad27be2f0d29ba716b7d76bca2ec47 (diff)
- fix potential memory and fd leak
ok benno, lum
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/region.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/usr.bin/mg/region.c b/usr.bin/mg/region.c
index baca932ca1f..7a21182d7d1 100644
--- a/usr.bin/mg/region.c
+++ b/usr.bin/mg/region.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: region.c,v 1.30 2012/04/11 17:51:10 lum Exp $ */
+/* $OpenBSD: region.c,v 1.31 2012/10/26 20:46:12 florian Exp $ */
/* This file is in the public domain. */
@@ -476,12 +476,16 @@ iomux(int fd)
int nfds;
char *text, *textcopy;
- if (getregion(&region) != TRUE)
+ if (getregion(&region) != TRUE) {
+ close(fd);
return (FALSE);
-
- if ((text = malloc(region.r_size + 1)) == NULL)
+ }
+
+ if ((text = malloc(region.r_size + 1)) == NULL) {
+ close(fd);
return (ABORT);
-
+ }
+
region_get_data(&region, text, region.r_size);
textcopy = text;
fcntl(fd, F_SETFL, O_NONBLOCK);
@@ -495,8 +499,11 @@ iomux(int fd)
bp = bfind("*Shell Command Output*", TRUE);
bp->b_flag |= BFREADONLY;
- if (bclear(bp) != TRUE)
+ if (bclear(bp) != TRUE) {
+ close(fd);
+ free(text);
return (FALSE);
+ }
pfd[0].fd = fd;
pfd[0].events = POLLIN | POLLOUT;