[PATCH] hugepages: close fd on error path in __get_thp_mode

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Apr 30 12:22:36 GMT 2026



On 30/04/26 09:19, Shamil Abdulaev wrote:
> H.J. Lu <hjl.tools@gmail.com <mailto:hjl.tools@gmail.com>>:
> 
>     On Thu, Apr 30, 2026 at 7:38 AM Shamil Abdulaev <ashamil435@gmail.com <mailto:ashamil435@gmail.com>> wrote:
>     >
>     > If __read_nocancel fails or overflows the buffer, the function returned
>     > without closing the /sys/kernel/mm/transparent_hugepage/enabled fd.
>     >
>     > Found while investigating BZ #34083.
>     >
>     > Signed-off-by: Shamil Abdulaev <ashamil435@gmail.com <mailto:ashamil435@gmail.com>>
>     > ---
>     >  sysdeps/unix/sysv/linux/hugepages.c | 2 +-
>     >  1 file changed, 1 insertion(+), 1 deletion(-)
>     >
>     > diff --git a/sysdeps/unix/sysv/linux/hugepages.c b/sysdeps/unix/sysv/linux/hugepages.c
>     > index 707a75c2a2..46e05151a3 100644
>     > --- a/sysdeps/unix/sysv/linux/hugepages.c
>     > +++ b/sysdeps/unix/sysv/linux/hugepages.c
>     > @@ -61,10 +61,10 @@ __get_thp_mode (void)
>     >
>     >    char str[sizeof(mode_always)];
>     >    ssize_t s = __read_nocancel (fd, str, sizeof (str));
>     > +  __close_nocancel (fd);
>     >    if (s >= sizeof str || s < 0)
>     >      return thp_mode_not_supported;
>     >    str[s] = '\0';
>     > -  __close_nocancel (fd);
>     >
>     >    if (s == sizeof (mode_always) - 1)
>     >      {
>     > --
>     > 2.54.0
>     >
> 
>     LGTM.
> 
>     Reviewed-by: H.J. Lu <hjl.tools@gmail.com <mailto:hjl.tools@gmail.com>>
> 
>     Thanks.
> 
>     -- 
>     H.J.
> 
> 
> Thanks for the review!
> 
> I don't have commit access to glibc -- could you push this on my behalf
> when convenient? Happy to rebase or address anything if needed.
> 
> Thanks,
> Shamil
> 

I will do it.


More information about the Libc-alpha mailing list