]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use gdb_dir_up in linux_proc_attach_tgid_threads
authorTom Tromey <tromey@adacore.com>
Thu, 7 Sep 2023 15:04:37 +0000 (09:04 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 1 Dec 2023 17:36:00 +0000 (10:36 -0700)
This changes linux_proc_attach_tgid_threads to use gdb_dir_up.  This
makes it robust against exceptions.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/nat/linux-procfs.c

index 95ecae443e47daf8cdf477fa104e7e07f9397e4a..c7d8ba2bd67ba3899a036d4e90976ec3c48918fb 100644 (file)
@@ -275,7 +275,6 @@ void
 linux_proc_attach_tgid_threads (pid_t pid,
                                linux_proc_attach_lwp_func attach_lwp)
 {
-  DIR *dir;
   char pathname[128];
   int new_threads_found;
   int iterations;
@@ -284,7 +283,7 @@ linux_proc_attach_tgid_threads (pid_t pid,
     return;
 
   xsnprintf (pathname, sizeof (pathname), "/proc/%ld/task", (long) pid);
-  dir = opendir (pathname);
+  gdb_dir_up dir (opendir (pathname));
   if (dir == NULL)
     {
       warning (_("Could not open %s."), pathname);
@@ -300,7 +299,7 @@ linux_proc_attach_tgid_threads (pid_t pid,
       struct dirent *dp;
 
       new_threads_found = 0;
-      while ((dp = readdir (dir)) != NULL)
+      while ((dp = readdir (dir.get ())) != NULL)
        {
          unsigned long lwp;
 
@@ -321,10 +320,8 @@ linux_proc_attach_tgid_threads (pid_t pid,
          iterations = -1;
        }
 
-      rewinddir (dir);
+      rewinddir (dir.get ());
     }
-
-  closedir (dir);
 }
 
 /* See linux-procfs.h.  */