* [patch] find_and_open_script: Fix failed fdopen
@ 2012-01-23 16:09 Jan Kratochvil
2012-01-23 16:14 ` Pedro Alves
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2012-01-23 16:09 UTC (permalink / raw)
To: gdb-patches
Hi,
just noticed if fdopen fails find_and_open_script returns generally invalid
result. I just read the code, not seen in practice.
No regressions on {x86_64,x86_64-m32,i686}-fedorarawhide-linux-gnu.
I will check it in.
Thanks,
Jan
gdb/
2012-01-23 Jan Kratochvil <jan.kratochvil@redhat.com>
* cli/cli-cmds.c (find_and_open_script): Handle failure of fdopen.
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -513,6 +513,17 @@ find_and_open_script (const char *script_file, int search_path,
do_cleanups (old_cleanups);
*streamp = fdopen (fd, FOPEN_RT);
+ if (*streamp == NULL)
+ {
+ int save_errno = errno;
+
+ if (full_pathp)
+ xfree (*full_pathp);
+ do_cleanups (old_cleanups);
+ errno = save_errno;
+ return 0;
+ }
+
return 1;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] find_and_open_script: Fix failed fdopen
2012-01-23 16:09 [patch] find_and_open_script: Fix failed fdopen Jan Kratochvil
@ 2012-01-23 16:14 ` Pedro Alves
2012-01-23 16:25 ` Jan Kratochvil
0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2012-01-23 16:14 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
On 01/23/2012 04:03 PM, Jan Kratochvil wrote:
> @@ -513,6 +513,17 @@ find_and_open_script (const char *script_file, int search_path,
> do_cleanups (old_cleanups);
>
> *streamp = fdopen (fd, FOPEN_RT);
> + if (*streamp == NULL)
> + {
> + int save_errno = errno;
> +
> + if (full_pathp)
> + xfree (*full_pathp);
> + do_cleanups (old_cleanups);
This do_cleanups doesn't look right. From the patch context, there's
already do_cleanups(old_cleanups) call a bit above.
--
Pedro Alves
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] find_and_open_script: Fix failed fdopen
2012-01-23 16:14 ` Pedro Alves
@ 2012-01-23 16:25 ` Jan Kratochvil
2012-01-23 16:38 ` Pedro Alves
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2012-01-23 16:25 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On Mon, 23 Jan 2012 17:09:17 +0100, Pedro Alves wrote:
> On 01/23/2012 04:03 PM, Jan Kratochvil wrote:
> > @@ -513,6 +513,17 @@ find_and_open_script (const char *script_file, int search_path,
> > do_cleanups (old_cleanups);
> >
> > *streamp = fdopen (fd, FOPEN_RT);
> > + if (*streamp == NULL)
> > + {
> > + int save_errno = errno;
> > +
> > + if (full_pathp)
> > + xfree (*full_pathp);
> > + do_cleanups (old_cleanups);
>
> This do_cleanups doesn't look right. From the patch context, there's
> already do_cleanups(old_cleanups) call a bit above.
Oops, thanks. Also missing close there.
Regards,
Jan
gdb/
2012-01-23 Jan Kratochvil <jan.kratochvil@redhat.com>
* cli/cli-cmds.c (find_and_open_script): Handle failure of fdopen.
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -513,6 +513,17 @@ find_and_open_script (const char *script_file, int search_path,
do_cleanups (old_cleanups);
*streamp = fdopen (fd, FOPEN_RT);
+ if (*streamp == NULL)
+ {
+ int save_errno = errno;
+
+ close (fd);
+ if (full_pathp)
+ xfree (*full_pathp);
+ errno = save_errno;
+ return 0;
+ }
+
return 1;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] find_and_open_script: Fix failed fdopen
2012-01-23 16:25 ` Jan Kratochvil
@ 2012-01-23 16:38 ` Pedro Alves
2012-01-23 16:43 ` [commit] " Jan Kratochvil
0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2012-01-23 16:38 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
On 01/23/2012 04:17 PM, Jan Kratochvil wrote:
> On Mon, 23 Jan 2012 17:09:17 +0100, Pedro Alves wrote:
>> This do_cleanups doesn't look right. From the patch context, there's
>> already do_cleanups(old_cleanups) call a bit above.
> Oops, thanks. Also missing close there.
Thanks. Looks correct to me now.
--
Pedro Alves
^ permalink raw reply [flat|nested] 5+ messages in thread
* [commit] [patch] find_and_open_script: Fix failed fdopen
2012-01-23 16:38 ` Pedro Alves
@ 2012-01-23 16:43 ` Jan Kratochvil
0 siblings, 0 replies; 5+ messages in thread
From: Jan Kratochvil @ 2012-01-23 16:43 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On Mon, 23 Jan 2012 17:31:02 +0100, Pedro Alves wrote:
> Thanks. Looks correct to me now.
Checked in:
http://sourceware.org/ml/gdb-cvs/2012-01/msg00185.html
Thanks,
Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-01-23 16:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-23 16:09 [patch] find_and_open_script: Fix failed fdopen Jan Kratochvil
2012-01-23 16:14 ` Pedro Alves
2012-01-23 16:25 ` Jan Kratochvil
2012-01-23 16:38 ` Pedro Alves
2012-01-23 16:43 ` [commit] " Jan Kratochvil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox