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

"H.J. Lu via Glibc-cvs" <[email protected]>
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ddd5c8b0b477420ea2c4ff4cadd2a9c9521f437b

commit ddd5c8b0b477420ea2c4ff4cadd2a9c9521f437b
Author: Shamil Abdulaev <[email protected]>
Date:   Thu Apr 30 02:37:39 2026 +0300

    hugepages: close fd on error path in __get_thp_mode
    
    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 <[email protected]>
    Reviewed-by: H.J. Lu <[email protected]>

Diff:
---
 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)
     {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.