]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hugepages: close fd on error path in __get_thp_mode
authorShamil Abdulaev <ashamil435@gmail.com>
Wed, 29 Apr 2026 23:37:39 +0000 (02:37 +0300)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 30 Apr 2026 12:24:51 +0000 (20:24 +0800)
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>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
sysdeps/unix/sysv/linux/hugepages.c

index 707a75c2a2964b390f131732529fc88a4c2454ba..46e05151a3c7dca96e2a85063337552822716d38 100644 (file)
@@ -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)
     {