summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-02-12 00:31:01 -0500
committermidipix <writeonce@midipix.org>2017-02-12 00:31:01 -0500
commit12fb1dbb0ed6b8b9b7c726b426a8c117e37c15fe (patch)
tree13f296a5270e6b1a1b68c5797adac1b20d45ade9 /src/util
parente3b1f2f9aa1116811817e8a664440b51e28a67d7 (diff)
downloadmdso-12fb1dbb0ed6b8b9b7c726b426a8c117e37c15fe.tar.bz2
mdso-12fb1dbb0ed6b8b9b7c726b426a8c117e37c15fe.tar.xz
mdso_create_implib_archive(): properly close fout upon intermediate failure.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mdso_create_implib_archive.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/util/mdso_create_implib_archive.c b/src/util/mdso_create_implib_archive.c
index 63bd9aa..c48c220 100644
--- a/src/util/mdso_create_implib_archive.c
+++ b/src/util/mdso_create_implib_archive.c
@@ -12,7 +12,7 @@
#include <mdso/mdso.h>
#include "mdso_errinfo_impl.h"
-static void mdso_free_uctx_vector(struct mdso_unit_ctx ** uctxv)
+static void mdso_free_uctx_vector(struct mdso_unit_ctx ** uctxv, FILE * fout)
{
struct mdso_unit_ctx ** puctx;
@@ -20,6 +20,7 @@ static void mdso_free_uctx_vector(struct mdso_unit_ctx ** uctxv)
mdso_free_unit_ctx(*puctx);
free(uctxv);
+ fclose(fout);
}
static int mdso_symcmp(const void * src, const void * dst)
@@ -43,18 +44,18 @@ int mdso_create_implib_archive(const struct mdso_driver_ctx * dctx)
if (!dctx->cctx->implib)
return MDSO_CUSTOM_ERROR(dctx,MDSO_ERR_INVALID_NAME);
- if (!(fout = mdso_create_archive(dctx,dctx->cctx->implib)))
- return MDSO_NESTED_ERROR(dctx);
-
for (unit=dctx->units; *unit; unit++)
(void)0;
if (!(uctxv = calloc(++unit - dctx->units,sizeof(*uctxv))))
return MDSO_SYSTEM_ERROR(dctx);
+ if (!(fout = mdso_create_archive(dctx,dctx->cctx->implib)))
+ return MDSO_NESTED_ERROR(dctx);
+
for (puctx=uctxv,unit=dctx->units; *unit; unit++) {
if (mdso_get_unit_ctx(dctx,*unit,puctx)) {
- mdso_free_uctx_vector(uctxv);
+ mdso_free_uctx_vector(uctxv,fout);
return MDSO_NESTED_ERROR(dctx);
}
}
@@ -68,7 +69,7 @@ int mdso_create_implib_archive(const struct mdso_driver_ctx * dctx)
symv = asym;
} else if (!(symv = calloc(nsym+1,sizeof(const char *)))) {
- mdso_free_uctx_vector(uctxv);
+ mdso_free_uctx_vector(uctxv,fout);
return MDSO_SYSTEM_ERROR(dctx);
}
@@ -78,12 +79,11 @@ int mdso_create_implib_archive(const struct mdso_driver_ctx * dctx)
qsort(symv,nsym,sizeof(*symv),mdso_symcmp);
ret = mdso_argen_common(dctx,symv,fout,0);
- fclose(fout);
if (symv != asym)
free(symv);
- mdso_free_uctx_vector(uctxv);
+ mdso_free_uctx_vector(uctxv,fout);
return ret ? MDSO_NESTED_ERROR(dctx) : 0;
}