summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libasm/ChangeLog4
-rw-r--r--libasm/asm_end.c15
-rw-r--r--src/ChangeLog4
-rw-r--r--src/strip.c5
-rw-r--r--tests/ChangeLog9
-rw-r--r--tests/newfile.c7
-rw-r--r--tests/newscn.c3
-rw-r--r--tests/update1.c1
-rw-r--r--tests/update2.c1
-rw-r--r--tests/update3.c1
-rw-r--r--tests/update4.c1
11 files changed, 43 insertions, 8 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;
}
diff --git a/src/ChangeLog b/src/ChangeLog
index 0d1e57d7..a4743314 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+ * strip.c: Close and reopen file when renaming.
+
+2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+
* addr2line.c: Don't assume unix file system conventions.
* size.c: Likewise.
* strip.c: Likewise.
diff --git a/src/strip.c b/src/strip.c
index 60f6700e..99d7dd13 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -2006,7 +2006,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
/* Create the real output file. First rename, then change the
mode. */
- if (rename (tmp_debug_fname, debug_fname) != 0
+ close (debug_fd);
+ int rename_result = rename (tmp_debug_fname, debug_fname);
+ debug_fd = open (debug_fname, O_RDONLY | O_BINARY);
+ if (rename_result != 0 || debug_fd == -1
#if HAVE_DECL_FCHMOD
|| fchmod (debug_fd, mode) != 0
#endif
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 5e29f821..b8de1386 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,14 @@
2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+ * newfile.c: Close the file when we're done and unlink it afterwards.
+ * newscn.c: Likewise.
+ * update1.c: Likewise.
+ * update2.c: Likewise.
+ * update3.c: Likewise.
+ * update4.c: Likewise.
+
+2017-05-04 Ulf Hermann <ulf.hermann@qt.io>
+
* asm-tst4.c: Don't assume unix file system conventions.
* asm-tst5.c: Likewise.
* asm-tst6.c: Likewise.
diff --git a/tests/newfile.c b/tests/newfile.c
index 5eabdcb7..a2793171 100644
--- a/tests/newfile.c
+++ b/tests/newfile.c
@@ -63,8 +63,6 @@ main (int argc, char *argv[] __attribute__ ((unused)))
printf ("cannot create temporary file: %m\n");
exit (1);
}
- /* Remove the file when we exit. */
- unlink (fname);
elf_version (EV_CURRENT);
elf = elf_begin (fd, ELF_C_WRITE, NULL);
@@ -166,5 +164,10 @@ main (int argc, char *argv[] __attribute__ ((unused)))
(void) elf_end (elf);
}
+ close (fd);
+
+ /* Remove the file when we exit. */
+ unlink (fname);
+
return result;
}
diff --git a/tests/newscn.c b/tests/newscn.c
index 466f2f68..de8951df 100644
--- a/tests/newscn.c
+++ b/tests/newscn.c
@@ -46,7 +46,6 @@ main (void)
fprintf (stderr, "Failed to open fdput file: %s\n", name);
exit (1);
}
- unlink (name);
elf = elf_begin (fd, ELF_C_WRITE, NULL);
if (elf == NULL)
@@ -62,5 +61,7 @@ main (void)
elf_end (elf);
close (fd);
+ unlink (name);
+
return 0;
}
diff --git a/tests/update1.c b/tests/update1.c
index a5716185..548c6d8a 100644
--- a/tests/update1.c
+++ b/tests/update1.c
@@ -121,6 +121,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
+ close (fd);
unlink (fname);
return 0;
diff --git a/tests/update2.c b/tests/update2.c
index 3e228796..1dcff3fc 100644
--- a/tests/update2.c
+++ b/tests/update2.c
@@ -144,6 +144,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
+ close (fd);
unlink (fname);
return 0;
diff --git a/tests/update3.c b/tests/update3.c
index d619bed0..9d4f8809 100644
--- a/tests/update3.c
+++ b/tests/update3.c
@@ -199,6 +199,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
+ close (fd);
unlink (fname);
return 0;
diff --git a/tests/update4.c b/tests/update4.c
index 8196b8c8..a762e0a0 100644
--- a/tests/update4.c
+++ b/tests/update4.c
@@ -351,6 +351,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
+ close (fd);
unlink (fname);
return 0;