]> Pileus Git - ~andy/gtk/commitdiff
Don't leak Registry key handles. (#516578)
authorTor Lillqvist <tml@novell.com>
Fri, 15 Feb 2008 00:26:40 +0000 (00:26 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Fri, 15 Feb 2008 00:26:40 +0000 (00:26 +0000)
2008-02-15  Tor Lillqvist  <tml@novell.com>

* gtk/gtkfilesystemwin32.c (get_viewable_logical_drives): Don't
leak Registry key handles. (#516578)

svn path=/trunk/; revision=19572

ChangeLog
gtk/gtkfilesystemwin32.c

index 6efe9f47fee4f8d811a6402acc986baaf68b0792..efb75fd245db22e9401275421b5a272e189f1b6d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-15  Tor Lillqvist  <tml@novell.com>
+
+       * gtk/gtkfilesystemwin32.c (get_viewable_logical_drives): Don't
+       leak Registry key handles. (#516578)
+
 2008-02-14  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkwindow-quartz.c: (gdk_window_focus): Using
index 55958eafe89bf4315bb22b29cc854b8c7d2dcc37..3fc8a088e42be4427c5836ced073c67cbd0c2a18 100644 (file)
@@ -346,33 +346,47 @@ static guint32
 get_viewable_logical_drives (void)
 {
   guint viewable_drives = GetLogicalDrives ();
-  HKEY my_key;
+  HKEY key;
 
   DWORD var_type = REG_DWORD; //the value's a REG_DWORD type
   DWORD no_drives_size = 4;
   DWORD no_drives;
   gboolean hklm_present = FALSE;
 
-  RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_READ, &my_key);
-  if (RegQueryValueEx (my_key, "NoDrives", NULL, &var_type, &no_drives, &no_drives_size) == ERROR_SUCCESS)
+  if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
+                   "Software\\Microsoft\\Windows\\"
+                   "CurrentVersion\\Policies\\Explorer",
+                   0, KEY_READ, &key) == ERROR_SUCCESS)
     {
-      // We need the bits that are set in viewable_drives, and unset in no_drives.
-      viewable_drives = viewable_drives & ~no_drives;
-      hklm_present = TRUE;
+      if (RegQueryValueEx (key, "NoDrives", NULL, &var_type,
+                          (LPBYTE) &no_drives, &no_drives_size) == ERROR_SUCCESS)
+       {
+         /* We need the bits that are set in viewable_drives, and
+          * unset in no_drives.
+          */
+         viewable_drives = viewable_drives & ~no_drives;
+         hklm_present = TRUE;
+       }
+      RegCloseKey (key);
     }
 
-  // If the key is present in HKLM then the one in HKCU should be ignored
+  /* If the key is present in HKLM then the one in HKCU should be ignored */
   if (!hklm_present)
     {
-      RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_READ, &my_key);
-    if (RegQueryValueEx (my_key, "NoDrives", NULL, &var_type, &no_drives, &no_drives_size) == ERROR_SUCCESS)
-      {
-       // We need the bits that are set in viewable_drives, and unset in no_drives.
-       viewable_drives = viewable_drives & ~no_drives;
-      }
-  }
+      if (RegOpenKeyEx (HKEY_CURRENT_USER,
+                       "Software\\Microsoft\\Windows\\"
+                       "CurrentVersion\\Policies\\Explorer",
+                       0, KEY_READ, &key) == ERROR_SUCCESS)
+       {
+         if (RegQueryValueEx (key, "NoDrives", NULL, &var_type,
+                              (LPBYTE) &no_drives, &no_drives_size) == ERROR_SUCCESS)
+           {
+             viewable_drives = viewable_drives & ~no_drives;
+           }
+         RegCloseKey (key);
+       }
+    }
 
-  RegCloseKey (my_key);
   return viewable_drives; 
 }