Fixed leaking file handle on BeOS during CD-ROM detection.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 14 Nov 2010 00:43:47 -0500
changeset 1131 267ac8c2eb6b
parent 1130 2db92d026ec6
child 1133 958df28c5449
Fixed leaking file handle on BeOS during CD-ROM detection.
src/platform_beos.cpp
--- a/src/platform_beos.cpp	Mon Oct 04 01:48:34 2010 -0400
+++ b/src/platform_beos.cpp	Sun Nov 14 00:43:47 2010 -0500
@@ -125,15 +125,16 @@
         else
         {
             bool add_it = false;
-            int devfd;
             device_geometry g;
 
             if (strcmp(e.name, "raw") == 0)  /* ignore partitions. */
             {
-                int devfd = open(name, O_RDONLY);
+                const int devfd = open(name, O_RDONLY);
                 if (devfd >= 0)
                 {
-                    if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0)
+                    const int rc = ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g));
+                    close(devfd);
+                    if (rc >= 0)
                     {
                         if (g.device_type == B_CD)
                         {
@@ -147,8 +148,6 @@
                     } /* if */
                 } /* if */
             } /* if */
-
-            close(devfd);
         } /* else */
     } /* while */
 } /* tryDir */