Skip to content

Commit

Permalink
always allocate metainfo_file_path dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
uno20001 committed Apr 21, 2020
1 parent 754793b commit a653e6d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion init.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ static void set_absolute_file_path(struct metafile *m)

/* if the file_path is already an absolute path just
return that */
if (m->metainfo_file_path && *m->metainfo_file_path == DIRSEP_CHAR)
if (m->metainfo_file_path && *m->metainfo_file_path == DIRSEP_CHAR) {
/* we need to reallocate the string, because we want to be able to
* free() it in cleanup_metafile(), and that would not be possible
* if m->metainfo_file_path pointed to a string from argv[]
*/
m->metainfo_file_path = strdup(m->metainfo_file_path);
FATAL_IF0(m->metainfo_file_path == NULL, "out of memory\n");
return;
}

/* first get the current working directory
using getcwd is a bit of a PITA */
Expand Down

0 comments on commit a653e6d

Please sign in to comment.