some cleanup checker fixes
authorTom Tromey <tromey@redhat.com>
Thu, 30 May 2013 16:24:36 +0000 (16:24 +0000)
committerTom Tromey <tromey@redhat.com>
Thu, 30 May 2013 16:24:36 +0000 (16:24 +0000)
Fix some bugs pointed out by the cleanup checker.  This one just fixes
some simple CLI reports, where CLI commands know that their caller
will do cleanups.  This an older style with few instances, so it is
simpler to fix them up than to teach the checker about it.

* cli/cli-cmds.c (cd_command, alias_command): Call do_cleanups.
* cli/cli-dump.c (restore_binary_file): Call do_cleanups.
* interps.c (interpreter_exec_cmd): Call do_cleanups.
* source.c (show_substitute_path_command): Call do_cleanups.
(unset_substitute_path_command, set_substitute_path_command):
Likewise.
* symfile.c (load_command): Call do_cleanups.

gdb/ChangeLog
gdb/cli/cli-cmds.c
gdb/cli/cli-dump.c
gdb/interps.c
gdb/source.c
gdb/symfile.c

index 971295dc6e72d8f31aa81b69938f13252d3b816b..e608b0a8579e53a631c1830cbdc2e8ea2aa1aed0 100644 (file)
@@ -1,3 +1,13 @@
+2013-05-30  Tom Tromey  <tromey@redhat.com>
+
+       * cli/cli-cmds.c (cd_command, alias_command): Call do_cleanups.
+       * cli/cli-dump.c (restore_binary_file): Call do_cleanups.
+       * interps.c (interpreter_exec_cmd): Call do_cleanups.
+       * source.c (show_substitute_path_command): Call do_cleanups.
+       (unset_substitute_path_command, set_substitute_path_command):
+       Likewise.
+       * symfile.c (load_command): Call do_cleanups.
+
 2013-05-30  Tom Tromey  <tromey@redhat.com>
 
        * contrib/cleanup_check.py: New file.
index cf88b6dd657e56242e2d175c1063a9c5926ab2f6..6ee767320b006a35a533a66561073e066776c9bc 100644 (file)
@@ -357,6 +357,7 @@ cd_command (char *dir, int from_tty)
   /* Found something other than leading repetitions of "/..".  */
   int found_real_path;
   char *p;
+  struct cleanup *cleanup;
 
   /* If the new directory is absolute, repeat is a no-op; if relative,
      repeat might be useful but is more likely to be a mistake.  */
@@ -366,7 +367,7 @@ cd_command (char *dir, int from_tty)
     dir = "~";
 
   dir = tilde_expand (dir);
-  make_cleanup (xfree, dir);
+  cleanup = make_cleanup (xfree, dir);
 
   if (chdir (dir) < 0)
     perror_with_name (dir);
@@ -450,6 +451,8 @@ cd_command (char *dir, int from_tty)
 
   if (from_tty)
     pwd_command ((char *) 0, 1);
+
+  do_cleanups (cleanup);
 }
 \f
 /* Show the current value of the 'script-extension' option.  */
@@ -1327,13 +1330,14 @@ alias_command (char *args, int from_tty)
   char *args2, *equals, *alias, *command;
   char **alias_argv, **command_argv;
   dyn_string_t alias_dyn_string, command_dyn_string;
+  struct cleanup *cleanup;
   static const char usage[] = N_("Usage: alias [-a] [--] ALIAS = COMMAND");
 
   if (args == NULL || strchr (args, '=') == NULL)
     error (_(usage));
 
   args2 = xstrdup (args);
-  make_cleanup (xfree, args2);
+  cleanup = make_cleanup (xfree, args2);
   equals = strchr (args2, '=');
   *equals = '\0';
   alias_argv = gdb_buildargv (args2);
@@ -1440,6 +1444,8 @@ alias_command (char *args, int from_tty)
                     command_argv[command_argc - 1],
                     class_alias, abbrev_flag, c_command->prefixlist);
     }
+
+  do_cleanups (cleanup);
 }
 \f
 /* Print a list of files and line numbers which a user may choose from
index 529e0a0fe42b19fb303da0d4f09d4df598bc93a4..208916cab1504a796d089ed472b1edb6cd631f63 100644 (file)
@@ -508,6 +508,7 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args)
 static void
 restore_binary_file (char *filename, struct callback_data *data)
 {
+  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
   FILE *file = fopen_with_cleanup (filename, FOPEN_RB);
   gdb_byte *buf;
   long len;
@@ -553,7 +554,7 @@ restore_binary_file (char *filename, struct callback_data *data)
   len = target_write_memory (data->load_start + data->load_offset, buf, len);
   if (len != 0)
     warning (_("restore: memory write failed (%s)."), safe_strerror (len));
-  return;
+  do_cleanups (cleanup);
 }
 
 static void
index bd23118227e9ab7f015c1693a3c4f8bd15794832..25500d6e835b16000ee78ca404c3d2d62b1c0fab 100644 (file)
@@ -409,12 +409,13 @@ interpreter_exec_cmd (char *args, int from_tty)
   unsigned int nrules;
   unsigned int i;
   int old_quiet, use_quiet;
+  struct cleanup *cleanup;
 
   if (args == NULL)
     error_no_arg (_("interpreter-exec command"));
 
   prules = gdb_buildargv (args);
-  make_cleanup_freeargv (prules);
+  cleanup = make_cleanup_freeargv (prules);
 
   nrules = 0;
   for (trule = prules; *trule != NULL; trule++)
@@ -452,6 +453,8 @@ interpreter_exec_cmd (char *args, int from_tty)
   interp_set (old_interp, 0);
   interp_set_quiet (interp_to_use, use_quiet);
   interp_set_quiet (old_interp, old_quiet);
+
+  do_cleanups (cleanup);
 }
 
 /* List the possible interpreters which could complete the given text.  */
index 710b90c9eb9758d5c3ae7992abaf6347d724d093..161a6c43d028f131a0e0b0cf5c7773ffbab38bed 100644 (file)
@@ -1840,9 +1840,10 @@ show_substitute_path_command (char *args, int from_tty)
   struct substitute_path_rule *rule = substitute_path_rules;
   char **argv;
   char *from = NULL;
+  struct cleanup *cleanup;
   
   argv = gdb_buildargv (args);
-  make_cleanup_freeargv (argv);
+  cleanup = make_cleanup_freeargv (argv);
 
   /* We expect zero or one argument.  */
 
@@ -1866,6 +1867,8 @@ show_substitute_path_command (char *args, int from_tty)
         printf_filtered ("  `%s' -> `%s'.\n", rule->from, rule->to);
       rule = rule->next;
     }
+
+  do_cleanups (cleanup);
 }
 
 /* Implement the "unset substitute-path" command.  */
@@ -1877,10 +1880,11 @@ unset_substitute_path_command (char *args, int from_tty)
   char **argv = gdb_buildargv (args);
   char *from = NULL;
   int rule_found = 0;
+  struct cleanup *cleanup;
 
   /* This function takes either 0 or 1 argument.  */
 
-  make_cleanup_freeargv (argv);
+  cleanup = make_cleanup_freeargv (argv);
   if (argv != NULL && argv[0] != NULL && argv[1] != NULL)
     error (_("Incorrect usage, too many arguments in command"));
 
@@ -1918,6 +1922,8 @@ unset_substitute_path_command (char *args, int from_tty)
     error (_("No substitution rule defined for `%s'"), from);
 
   forget_cached_source_info ();
+
+  do_cleanups (cleanup);
 }
 
 /* Add a new source path substitution rule.  */
@@ -1927,9 +1933,10 @@ set_substitute_path_command (char *args, int from_tty)
 {
   char **argv;
   struct substitute_path_rule *rule;
+  struct cleanup *cleanup;
   
   argv = gdb_buildargv (args);
-  make_cleanup_freeargv (argv);
+  cleanup = make_cleanup_freeargv (argv);
 
   if (argv == NULL || argv[0] == NULL || argv [1] == NULL)
     error (_("Incorrect usage, too few arguments in command"));
@@ -1956,6 +1963,8 @@ set_substitute_path_command (char *args, int from_tty)
 
   add_substitute_path_rule (argv[0], argv[1]);
   forget_cached_source_info ();
+
+  do_cleanups (cleanup);
 }
 
 \f
index e9609b26e0d2a311ac419aa8b1b717d9e9794e04..360f9993ec65e4c282cfd659f6aad0fc78dce7f5 100644 (file)
@@ -1772,6 +1772,8 @@ find_sym_fns (bfd *abfd)
 static void
 load_command (char *arg, int from_tty)
 {
+  struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
+
   dont_repeat ();
 
   /* The user might be reloading because the binary has changed.  Take
@@ -1821,6 +1823,8 @@ load_command (char *arg, int from_tty)
   /* After re-loading the executable, we don't really know which
      overlays are mapped any more.  */
   overlay_cache_invalid = 1;
+
+  do_cleanups (cleanup);
 }
 
 /* This version of "load" should be usable for any target.  Currently
This page took 0.034369 seconds and 4 git commands to generate.