summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-10-23 23:11:52 -0400
committermidipix <writeonce@midipix.org>2016-11-11 00:22:48 -0500
commitb023b752cd6626b338ea72357bf9e61a40c816e6 (patch)
tree19452586116d1383ebc4755cabb816430c47371e
parent4eae2803e736b7b083652c733b121fad00cc6672 (diff)
downloadmdso-b023b752cd6626b338ea72357bf9e61a40c816e6.tar.bz2
mdso-b023b752cd6626b338ea72357bf9e61a40c816e6.tar.xz
mdso_create_output(): do not leak fdout upon fopen failure.
-rw-r--r--src/output/mdso_create_output.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/output/mdso_create_output.c b/src/output/mdso_create_output.c
index 3eb95bc..5bbc50d 100644
--- a/src/output/mdso_create_output.c
+++ b/src/output/mdso_create_output.c
@@ -21,6 +21,7 @@ FILE * mdso_create_output(
struct mdso_driver_ctx_impl * ictx;
uintptr_t addr;
int fdout;
+ FILE * fout;
if (!dctx->cctx->dstdir)
return stdout;
@@ -33,5 +34,10 @@ FILE * mdso_create_output(
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
return 0;
- return fdopen(fdout,"w");
+ if (!(fout = fdopen(fdout,"w"))) {
+ close(fdout);
+ return 0;
+ }
+
+ return fout;
}