浏览代码

Handle potential out of memory condition when working with hints

Sam Lantinga 3 年之前
父节点
当前提交
ba62ead5ec
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      src/SDL_hints.c

+ 5 - 0
src/SDL_hints.c

@@ -178,6 +178,11 @@ SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
             return;
         }
         hint->name = SDL_strdup(name);
+        if (!hint->name) {
+            SDL_free(hint);
+            SDL_OutOfMemory();
+            return;
+        }
         hint->value = NULL;
         hint->priority = SDL_HINT_DEFAULT;
         hint->callbacks = NULL;