collect2: Fix missing cleanups.

Message ID 20211013140052.18988-1-iain@sandoe.co.uk
State Committed
Commit 43ae43f654749d291d871ca6ef7c96ea16580fad
Headers
Series collect2: Fix missing cleanups. |

Commit Message

Iain Sandoe Oct. 13, 2021, 2 p.m. UTC
  The code that checks to see if objects have LTO content via
simple-object was not releasing resources, fixed thus.

tested on x86_64, powerpc64le linux, powerpc-aix, i686,x86_64-darwin,
OK for master and backports?
thanks
Iain

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

gcc/ChangeLog:

	* collect2.c (is_lto_object_file): Release simple-object
	resources, close files.
---
 gcc/collect2.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

Richard Biener Oct. 13, 2021, 2:19 p.m. UTC | #1
On Wed, Oct 13, 2021 at 4:00 PM Iain Sandoe <iains.gcc@gmail.com> wrote:
>
> The code that checks to see if objects have LTO content via
> simple-object was not releasing resources, fixed thus.
>
> tested on x86_64, powerpc64le linux, powerpc-aix, i686,x86_64-darwin,
> OK for master and backports?

OK.

Richard.

> thanks
> Iain
>
> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
>
> gcc/ChangeLog:
>
>         * collect2.c (is_lto_object_file): Release simple-object
>         resources, close files.
> ---
>  gcc/collect2.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/collect2.c b/gcc/collect2.c
> index cf04a58ba4d..d47fe3f9195 100644
> --- a/gcc/collect2.c
> +++ b/gcc/collect2.c
> @@ -2299,10 +2299,15 @@ is_lto_object_file (const char *prog_name)
>                                                         LTO_SEGMENT_NAME,
>                                                         &errmsg, &err);
>    if (!inobj)
> -    return false;
> +    {
> +      close (infd);
> +      return false;
> +    }
>
>    errmsg = simple_object_find_sections (inobj, has_lto_section,
>                                         (void *) &found, &err);
> +  simple_object_release_read (inobj);
> +  close (infd);
>    if (! errmsg && found)
>      return true;
>
> --
> 2.24.3 (Apple Git-128)
>
  

Patch

diff --git a/gcc/collect2.c b/gcc/collect2.c
index cf04a58ba4d..d47fe3f9195 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -2299,10 +2299,15 @@  is_lto_object_file (const char *prog_name)
 							LTO_SEGMENT_NAME,
 							&errmsg, &err);
   if (!inobj)
-    return false;
+    {
+      close (infd);
+      return false;
+    }
 
   errmsg = simple_object_find_sections (inobj, has_lto_section,
 					(void *) &found, &err);
+  simple_object_release_read (inobj);
+  close (infd);
   if (! errmsg && found)
     return true;