Add simple reference-counted string allocator and use it for passing

around references to the sudoers path.  This lets us avoid making
copies of the sudoers path for the errorfile as well as each Defaults
entry.
This commit is contained in:
Todd C. Miller
2016-11-11 16:18:27 -07:00
parent b5e3a7aef2
commit 90995c0acf
10 changed files with 177 additions and 78 deletions

View File

@@ -1030,8 +1030,8 @@ export_sudoers(const char *sudoers_path, const char *export_path,
if (!quiet)
sudo_warnx(U_("failed to parse %s file, unknown error"), sudoers_path);
parse_error = true;
free(errorfile);
if ((errorfile = strdup(sudoers_path)) == NULL)
rcstr_delref(errorfile);
if ((errorfile = rcstr_dup(sudoers_path)) == NULL)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
}
ret = !parse_error;