aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/fish.cpp
diff options
context:
space:
mode:
authorGravatar Andreas Nordal <andreas_nordal_4@hotmail.com>2016-03-15 22:03:27 +0100
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-03-22 11:43:58 -0700
commit2a4a539d8696bcd61bac5d558795c2eaa3f78c70 (patch)
tree77f829119ca3c17b809217730648537dec7f9329 /src/fish.cpp
parenta81bd697a8237ada71a24ebbf58fcf1b127e8f34 (diff)
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`.
Diffstat (limited to 'src/fish.cpp')
-rw-r--r--src/fish.cpp28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/fish.cpp b/src/fish.cpp
index 048c9cbe..bb898be5 100644
--- a/src/fish.cpp
+++ b/src/fish.cpp
@@ -550,34 +550,30 @@ int main(int argc, char **argv)
}
reader_exit(0, 0);
}
+ else if (my_optind == argc)
+ {
+ // Interactive mode
+ check_running_fishd();
+ res = reader_read(STDIN_FILENO, empty_ios);
+ }
else
{
- if (my_optind == argc)
+ char *file = *(argv+(my_optind++));
+ int fd = open(file, O_RDONLY);
+ if (fd == -1)
{
- // Interactive mode
- check_running_fishd();
- res = reader_read(STDIN_FILENO, empty_ios);
+ perror(file);
}
else
{
- char **ptr;
- char *file = *(argv+(my_optind++));
- int i;
- int fd;
-
-
- if ((fd = open(file, O_RDONLY)) == -1)
- {
- wperror(L"open");
- return 1;
- }
-
// 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)