mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Fix memory leak, error message when failing to open input file
The early return skipped all cleanup. This problem is a case for the classic "goto fail" paradigm, but this change instead makes a few adjustments to take advantage of a previously unused level of indentation to conditionally execute the success path. The error message now prints the filename instead of "open", which should be more idiomatic. Tip: This patch makes sense if viewed with `git show --ignore-space-change`.
This commit is contained in:
parent
a81bd697a8
commit
2a4a539d86
1 changed files with 12 additions and 16 deletions
20
src/fish.cpp
20
src/fish.cpp
|
@ -550,9 +550,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
reader_exit(0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (my_optind == argc)
|
||||
else if (my_optind == argc)
|
||||
{
|
||||
// Interactive mode
|
||||
check_running_fishd();
|
||||
|
@ -560,24 +558,22 @@ int main(int argc, char **argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
char **ptr;
|
||||
char *file = *(argv+(my_optind++));
|
||||
int i;
|
||||
int fd;
|
||||
|
||||
|
||||
if ((fd = open(file, O_RDONLY)) == -1)
|
||||
int fd = open(file, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
wperror(L"open");
|
||||
return 1;
|
||||
perror(file);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// OK to not do this atomically since we cannot have gone multithreaded yet
|
||||
set_cloexec(fd);
|
||||
|
||||
if (*(argv+my_optind))
|
||||
{
|
||||
wcstring sb;
|
||||
char **ptr;
|
||||
int i;
|
||||
for (i=1,ptr = argv+my_optind; *ptr; i++, ptr++)
|
||||
{
|
||||
if (i != 1)
|
||||
|
|
Loading…
Reference in a new issue