mirror of
https://github.com/postgres/postgres.git
synced 2026-03-27 04:44:15 -04:00
Fix small memory leak in get_dbname_oid_list_from_mfile().
Coverity complained that this function leaked the dumpdirpath string, which it did. But we don't need to make a copy at all, because there's not really any point in trimming trailing slashes from the directory name here. If that were needed, the initial file_exists_in_directory() test would have failed, since it doesn't bother with that (and neither does anyplace else in this file). Moreover, if we did want that, reimplementing canonicalize_path() poorly is not the way to proceed. Arguably, all of this code should be reexamined with an eye to using src/port/path.c's facilities, but for today I'll settle for getting rid of the memory leak.
This commit is contained in:
parent
a793677e57
commit
bb53b8d359
1 changed files with 3 additions and 13 deletions
|
|
@ -68,7 +68,7 @@ static int restore_all_databases(const char *inputFileSpec,
|
|||
static int get_dbnames_list_to_restore(PGconn *conn,
|
||||
SimplePtrList *dbname_oid_list,
|
||||
SimpleStringList db_exclude_patterns);
|
||||
static int get_dbname_oid_list_from_mfile(const char *dumpdirpatharg,
|
||||
static int get_dbname_oid_list_from_mfile(const char *dumpdirpath,
|
||||
SimplePtrList *dbname_oid_list);
|
||||
|
||||
/*
|
||||
|
|
@ -1051,14 +1051,13 @@ get_dbnames_list_to_restore(PGconn *conn,
|
|||
* Returns, total number of database names in map.dat file.
|
||||
*/
|
||||
static int
|
||||
get_dbname_oid_list_from_mfile(const char *dumpdirpatharg, SimplePtrList *dbname_oid_list)
|
||||
get_dbname_oid_list_from_mfile(const char *dumpdirpath,
|
||||
SimplePtrList *dbname_oid_list)
|
||||
{
|
||||
StringInfoData linebuf;
|
||||
FILE *pfile;
|
||||
char map_file_path[MAXPGPATH];
|
||||
int count = 0;
|
||||
int len;
|
||||
char *dumpdirpath = pstrdup(dumpdirpatharg);
|
||||
|
||||
/*
|
||||
* If there is no map.dat file in the dump, then return from here as there
|
||||
|
|
@ -1070,15 +1069,6 @@ get_dbname_oid_list_from_mfile(const char *dumpdirpatharg, SimplePtrList *dbname
|
|||
return 0;
|
||||
}
|
||||
|
||||
len = strlen(dumpdirpath);
|
||||
|
||||
/* Trim slash from directory name. */
|
||||
while (len > 1 && dumpdirpath[len - 1] == '/')
|
||||
{
|
||||
dumpdirpath[len - 1] = '\0';
|
||||
len--;
|
||||
}
|
||||
|
||||
snprintf(map_file_path, MAXPGPATH, "%s/map.dat", dumpdirpath);
|
||||
|
||||
/* Open map.dat file. */
|
||||
|
|
|
|||
Loading…
Reference in a new issue