collect2: Fix missing cleanups.

Message ID 20211013140052.18988-1-iain@sandoe.co.uk
State New
Headers show
Series
  • collect2: Fix missing cleanups.
Related show

Commit Message

Jason Merrill via Gcc-patches Oct. 13, 2021, 2 p.m.
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(-)

-- 
2.24.3 (Apple Git-128)

Comments

Jason Merrill via Gcc-patches Oct. 13, 2021, 2:19 p.m. | #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;