Fix NULL-pointer dereference if can't find registry entry.
authorIan Elliott <ian@LunarG.com>
Fri, 3 Apr 2015 19:13:01 +0000 (13:13 -0600)
committerIan Elliott <ian@LunarG.com>
Fri, 3 Apr 2015 19:13:01 +0000 (13:13 -0600)
loader/loader.c

index 47cfb36..1de7c84 100644 (file)
@@ -179,7 +179,7 @@ static char *loader_get_registry_and_env(const char *env_var,
     registry_str = loader_get_registry_string(HKEY_LOCAL_MACHINE,
                                               "Software\\XGL",
                                               registry_value);
-    registry_len = strlen(registry_str);
+    registry_len = (registry_str) ? strlen(registry_str) : 0;
 
     rtn_len = env_len + registry_len + 1;
     if (rtn_len <= 2) {
@@ -205,7 +205,9 @@ static char *loader_get_registry_and_env(const char *env_var,
         _snprintf(rtn_str, rtn_len, "%s", registry_str);
     }
 
-    free(registry_str);
+    if (registry_str) {
+      free(registry_str);
+    }
 
     return(rtn_str);
 }