Remove an xfree from add_path
authorTom Tromey <tom@tromey.com>
Sun, 24 Oct 2021 21:58:24 +0000 (15:58 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 7 Dec 2021 21:20:11 +0000 (14:20 -0700)
This removes a temporary \0 assignment and an xfree from add_path,
replacing it with a simpler use of std::string.

gdb/source.c

index 3810af83042d254fe4a6d667d402cd6dd59f65fb..d91389e28b78161f9845fe1076976d7cb18752c2 100644 (file)
@@ -660,15 +660,10 @@ add_path (const char *dirname, char **which_path, int parse_separators)
           more.  */
        if (prefix)
          {
-           char *temp, c;
-
-           c = old[prefix];
-           old[prefix] = '\0';
-           temp = concat (old, tinybuf, name, (char *)NULL);
-           old[prefix] = c;
-           *which_path = concat (temp, "", &old[prefix], (char *) NULL);
-           prefix = strlen (temp);
-           xfree (temp);
+           std::string temp (old, prefix);
+           *which_path = concat (temp.c_str (), tinybuf, name, &old[prefix],
+                                 (char *) nullptr);
+           prefix = temp.length ();
          }
        else
          {