summaryrefslogtreecommitdiffstats
path: root/libasm
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-04-11 16:31:27 +0200
committerUlf Hermann <ulf.hermann@qt.io>2017-05-08 09:47:06 +0000
commit14192f5767b3388d9f6a1cdc8cadfb047b7a1f6a (patch)
treedfe8fa844fb85a22f7d9d4e09f3a1d8e2e8103bc /libasm
parent9f59b055f56ccebaa3d272d153c74fb889958a8a (diff)
Close files before renaming or unlinking them
On windows we cannot rename or unlink open files. Change-Id: Ieae8712266a3e65217580d4936219767c5f26f21 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'libasm')
-rw-r--r--libasm/ChangeLog4
-rw-r--r--libasm/asm_end.c15
2 files changed, 15 insertions, 4 deletions
diff --git a/libasm/ChangeLog b/libasm/ChangeLog
index 2b499c70..0e676572 100644
--- a/libasm/ChangeLog
+++ b/libasm/ChangeLog
@@ -1,5 +1,9 @@
2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+ * asm_end.c: Rename the output file only after freeing resources.
+
+2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+
* asm_end.c: Don't fchmod the new file if fchmod is unavailable.
2017-02-28 Ulf Hermann <ulf.hermann@qt.io>
diff --git a/libasm/asm_end.c b/libasm/asm_end.c
index 7fabe94d..7891fbb5 100644
--- a/libasm/asm_end.c
+++ b/libasm/asm_end.c
@@ -521,16 +521,23 @@ asm_end (AsmCtx_t *ctx)
}
#endif
+ char *tmp_fname = strdup (ctx->tmp_fname);
+ char *fname = strdup (ctx->fname);
+
+ /* Free the resources. */
+ __libasm_finictx (ctx);
+
/* Rename output file. */
- if (rename (ctx->tmp_fname, ctx->fname) != 0)
+ result = rename (tmp_fname, fname);
+ free (tmp_fname);
+ free (fname);
+
+ if (result != 0)
{
__libasm_seterrno (ASM_E_CANNOT_RENAME);
return -1;
}
- /* Free the resources. */
- __libasm_finictx (ctx);
-
return 0;
}