+2017-08-03 Tom Tromey <tom@tromey.com>
+
+ * utils.h (make_cleanup_free_so): Remove.
+ * utils.c (do_free_so, make_cleanup_free_so): Remove.
+ * solist.h (struct so_deleter): New.
+ (so_list_up): New typedef.
+ * solib-svr4.c (svr4_read_so_list): Use so_list_up.
+
2017-08-03 Tom Tromey <tom@tromey.com>
* utils.h (make_cleanup_restore_current_language): Remove.
for (; lm != 0; prev_lm = lm, lm = next_lm)
{
- struct so_list *newobj;
- struct cleanup *old_chain;
int errcode;
char *buffer;
- newobj = XCNEW (struct so_list);
- old_chain = make_cleanup_free_so (newobj);
+ so_list_up newobj (XCNEW (struct so_list));
lm_info_svr4 *li = lm_info_read (lm);
newobj->lm_info = li;
if (li == NULL)
- {
- do_cleanups (old_chain);
- return 0;
- }
+ return 0;
next_lm = li->l_next;
warning (_("Corrupted shared library list: %s != %s"),
paddress (target_gdbarch (), prev_lm),
paddress (target_gdbarch (), li->l_prev));
- do_cleanups (old_chain);
return 0;
}
first_l_name = li->l_name;
info->main_lm_addr = li->lm_addr;
- do_cleanups (old_chain);
continue;
}
if (first_l_name == 0 || li->l_name != first_l_name)
warning (_("Can't read pathname for load map: %s."),
safe_strerror (errcode));
- do_cleanups (old_chain);
continue;
}
/* If this entry has no name, or its name matches the name
for the main executable, don't include it in the list. */
if (! newobj->so_name[0] || match_main (newobj->so_name))
- {
- do_cleanups (old_chain);
- continue;
- }
+ continue;
- discard_cleanups (old_chain);
newobj->next = 0;
- **link_ptr_ptr = newobj;
- *link_ptr_ptr = &newobj->next;
+ /* Don't free it now. */
+ **link_ptr_ptr = newobj.release ();
+ *link_ptr_ptr = &(**link_ptr_ptr)->next;
}
return 1;
/* Free the memory associated with a (so_list *). */
void free_so (struct so_list *so);
+/* A deleter that calls free_so. */
+struct so_deleter
+{
+ void operator() (struct so_list *so) const
+ {
+ free_so (so);
+ }
+};
+
+/* A unique pointer to a so_list. */
+typedef std::unique_ptr<so_list, so_deleter> so_list_up;
+
/* Return address of first so_list entry in master shared object list. */
struct so_list *master_so_list (void);
return make_cleanup (do_value_free, value);
}
-/* Helper for make_cleanup_free_so. */
-
-static void
-do_free_so (void *arg)
-{
- struct so_list *so = (struct so_list *) arg;
-
- free_so (so);
-}
-
-/* Make cleanup handler calling free_so for SO. */
-
-struct cleanup *
-make_cleanup_free_so (struct so_list *so)
-{
- return make_cleanup (do_free_so, so);
-}
-
/* Helper function for make_cleanup_clear_parser_state. */
static void