瀏覽代碼

Fix double-free warning in src/hidapi/linux/hid.c

(cherry picked from commit ae5ce258cf4fdcfdd8533b22adc16f139e8f72a8)
Petar Popovic 1 月之前
父節點
當前提交
d31b239288
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      src/hidapi/linux/hid.c

+ 1 - 1
src/hidapi/linux/hid.c

@@ -134,7 +134,6 @@ static wchar_t *utf8_to_wchar_t(const char *utf8)
  * Use register_error_str(NULL) to free the error message completely. */
  * Use register_error_str(NULL) to free the error message completely. */
 static void register_error_str(wchar_t **error_str, const char *msg)
 static void register_error_str(wchar_t **error_str, const char *msg)
 {
 {
-	free(*error_str);
 #ifdef HIDAPI_USING_SDL_RUNTIME
 #ifdef HIDAPI_USING_SDL_RUNTIME
 	/* Thread-safe error handling */
 	/* Thread-safe error handling */
 	if (msg) {
 	if (msg) {
@@ -143,6 +142,7 @@ static void register_error_str(wchar_t **error_str, const char *msg)
 		SDL_ClearError();
 		SDL_ClearError();
 	}
 	}
 #else
 #else
+	free(*error_str);
 	*error_str = utf8_to_wchar_t(msg);
 	*error_str = utf8_to_wchar_t(msg);
 #endif
 #endif
 }
 }