aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-11-21 16:26:20 -0700
committerTom Tromey <tom@tromey.com>2017-01-10 19:14:11 -0700
commitbef155c3e8a995fcdb1c2ba5aba012eb653d9f30 (patch)
tree50b429ebc20397db99dbb753e5ce9f72fe7e9fde /gdb/dwarf2read.c
parent192b62ce0b4bb5c61188f570e127a26d2c32f716 (diff)
downloadgdb-bef155c3e8a995fcdb1c2ba5aba012eb653d9f30.zip
gdb-bef155c3e8a995fcdb1c2ba5aba012eb653d9f30.tar.gz
gdb-bef155c3e8a995fcdb1c2ba5aba012eb653d9f30.tar.bz2
Introduce and use gdb::unlinker
This introduces a new class, gdb::unlinker, that unlinks a file in the destructor. The user of this class has the option to preserve the file instead, by calling the "keep" method. This patch then changes the spots in gdb that use unlink in a cleanup to use this class instead. In one spot I went ahead and removed all the cleanups from the function. This fixes one latent bug -- do_bfd_delete_cleanup could refer to freed memory, by decref'ing the BFD before using its filename. 2017-01-10 Tom Tromey <tom@tromey.com> * record-full.c (record_full_save_cleanups): Remove. (record_full_save): Use gdb::unlinker. * gcore.c (do_bfd_delete_cleanup): Remove. (gcore_command): Use gdb::unlinker, unique_xmalloc_ptr. Remove cleanups. * dwarf2read.c (unlink_if_set): Remove. (write_psymtabs_to_index): Use gdb::unlinker. * common/gdb_unlinker.h: New file.
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c21
1 files changed, 5 insertions, 16 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 8a66848..dfb79c9 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -69,6 +69,7 @@
#include "filestuff.h"
#include "build-id.h"
#include "namespace.h"
+#include "common/gdb_unlinker.h"
#include <fcntl.h>
#include <sys/types.h>
@@ -23165,16 +23166,6 @@ write_obstack (FILE *file, struct obstack *obstack)
error (_("couldn't data write to file"));
}
-/* Unlink a file if the argument is not NULL. */
-
-static void
-unlink_if_set (void *p)
-{
- char **filename = (char **) p;
- if (*filename)
- unlink (*filename);
-}
-
/* A helper struct used when iterating over debug_types. */
struct signatured_type_index_data
{
@@ -23259,7 +23250,7 @@ static void
write_psymtabs_to_index (struct objfile *objfile, const char *dir)
{
struct cleanup *cleanup;
- char *filename, *cleanup_filename;
+ char *filename;
struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
struct obstack cu_list, types_cu_list;
int i;
@@ -23289,8 +23280,7 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
if (!out_file)
error (_("Can't open `%s' for writing"), filename);
- cleanup_filename = filename;
- make_cleanup (unlink_if_set, &cleanup_filename);
+ gdb::unlinker unlink_file (filename);
symtab = create_mapped_symtab ();
make_cleanup (cleanup_mapped_symtab, symtab);
@@ -23429,9 +23419,8 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
fclose (out_file);
- /* We want to keep the file, so we set cleanup_filename to NULL
- here. See unlink_if_set. */
- cleanup_filename = NULL;
+ /* We want to keep the file. */
+ unlink_file.keep ();
do_cleanups (cleanup);
}