From bc7a019e8fa3dd1ff9d2b4cf978f321d29b92592 Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 10 Oct 2009 18:26:27 +0200 Subject: [PATCH] Fixed cookie memory leak, changed cookies to only be created once. --- src/zr/playerclasses/classevents.inc | 19 +++++++------------ src/zr/playerclasses/clientoverlays.inc | 9 +++------ src/zr/weapons/zmarket.inc | 18 ++++++------------ src/zr/zhp.inc | 9 +++------ 4 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/zr/playerclasses/classevents.inc b/src/zr/playerclasses/classevents.inc index fa0e96e..a5e7fbe 100644 --- a/src/zr/playerclasses/classevents.inc +++ b/src/zr/playerclasses/classevents.inc @@ -25,24 +25,19 @@ ClassOnCookiesCreate() // Forward event to sub-modules. ClassOverlayOnCookiesCreate(); - // Close cookie handles if they already exist. - if (g_hClassCookieClassSelected[ZR_CLASS_TEAM_HUMANS] != INVALID_HANDLE) + // Create cookie handles only if they don't exist. + if (g_hClassCookieClassSelected[ZR_CLASS_TEAM_HUMANS] == INVALID_HANDLE) { - CloseHandle(g_hClassCookieClassSelected[ZR_CLASS_TEAM_HUMANS]); + g_hClassCookieClassSelected[ZR_CLASS_TEAM_HUMANS] = RegClientCookie("zr_humanclass", "The last human class selected.", CookieAccess_Protected); } - if (g_hClassCookieClassSelected[ZR_CLASS_TEAM_ZOMBIES] != INVALID_HANDLE) + if (g_hClassCookieClassSelected[ZR_CLASS_TEAM_ZOMBIES] == INVALID_HANDLE) { - CloseHandle(g_hClassCookieClassSelected[ZR_CLASS_TEAM_ZOMBIES]); + g_hClassCookieClassSelected[ZR_CLASS_TEAM_ZOMBIES] = RegClientCookie("zr_zombieclass", "The last zombie class selected.", CookieAccess_Protected); } - if (g_hClassCookieClassSelected[ZR_CLASS_TEAM_ADMINS] != INVALID_HANDLE) + if (g_hClassCookieClassSelected[ZR_CLASS_TEAM_ADMINS] == INVALID_HANDLE) { - CloseHandle(g_hClassCookieClassSelected[ZR_CLASS_TEAM_ADMINS]); + g_hClassCookieClassSelected[ZR_CLASS_TEAM_ADMINS] = RegClientCookie("zr_adminclass", "The last admin mode class selected.", CookieAccess_Protected); } - - // Create class index cookies. - g_hClassCookieClassSelected[ZR_CLASS_TEAM_HUMANS] = RegClientCookie("zr_humanclass", "The last human class selected.", CookieAccess_Protected); - g_hClassCookieClassSelected[ZR_CLASS_TEAM_ZOMBIES] = RegClientCookie("zr_zombieclass", "The last zombie class selected.", CookieAccess_Protected); - g_hClassCookieClassSelected[ZR_CLASS_TEAM_ADMINS] = RegClientCookie("zr_adminclass", "The last admin mode class selected.", CookieAccess_Protected); } /** diff --git a/src/zr/playerclasses/clientoverlays.inc b/src/zr/playerclasses/clientoverlays.inc index b470d1c..8f805d9 100644 --- a/src/zr/playerclasses/clientoverlays.inc +++ b/src/zr/playerclasses/clientoverlays.inc @@ -76,14 +76,11 @@ ClassOverlayOnCommandsHook() */ ClassOverlayOnCookiesCreate() { - // Close cookie handle if it already exist. - if (g_hOverlayEnabledCookie != INVALID_HANDLE) + // Create cookie handle only if it don't exist. + if (g_hOverlayEnabledCookie == INVALID_HANDLE) { - CloseHandle(g_hOverlayEnabledCookie); + g_hOverlayEnabledCookie = RegClientCookie(CLASSOVERLAY_COOKIE_ENABLED, "The toggle state of the class overlay.", CookieAccess_Protected); } - - // Create overlay cookie. - g_hOverlayEnabledCookie = RegClientCookie(CLASSOVERLAY_COOKIE_ENABLED, "The toggle state of the class overlay.", CookieAccess_Protected); } /** diff --git a/src/zr/weapons/zmarket.inc b/src/zr/weapons/zmarket.inc index f3c64d3..d3f5751 100644 --- a/src/zr/weapons/zmarket.inc +++ b/src/zr/weapons/zmarket.inc @@ -70,15 +70,12 @@ ZMarketOnCommandsCreate() ZMarketOnCookiesCreate() { - // Close auto-rebuy cookie handle if it already exist. - if (g_hZMarketAutoRebuyCookie != INVALID_HANDLE) + // Create auto-rebuy cookie handle if doesn't exist. + if (g_hZMarketAutoRebuyCookie == INVALID_HANDLE) { - CloseHandle(g_hZMarketAutoRebuyCookie); + g_hZMarketAutoRebuyCookie = RegClientCookie(ZMARKET_COOKIE_AUTOREBUY, "The toggle state of auto-rebuy.", CookieAccess_Protected); } - // Create auto-rebuy cookie. - g_hZMarketAutoRebuyCookie = RegClientCookie(ZMARKET_COOKIE_AUTOREBUY, "The toggle state of auto-rebuy.", CookieAccess_Protected); - decl String:rebuycookiename[32]; decl String:rebuycookiedesc[64]; @@ -89,14 +86,11 @@ ZMarketOnCookiesCreate() Format(rebuycookiename, sizeof(rebuycookiename), "%s_%d", ZMARKET_COOKIE_REBUY, x); Format(rebuycookiedesc, sizeof(rebuycookiedesc), "Current loadout weapon for slot %d", x); - // Close loadout cookie handle if it already exist. - if (g_hZMarketLoadoutCookie[x] != INVALID_HANDLE) + // Create loadout cookie handle if it doesn't exist. + if (g_hZMarketLoadoutCookie[x] == INVALID_HANDLE) { - CloseHandle(g_hZMarketLoadoutCookie[x]); + g_hZMarketLoadoutCookie[x] = RegClientCookie(rebuycookiename, rebuycookiedesc, CookieAccess_Protected); } - - // Create loadout cookie. - g_hZMarketLoadoutCookie[x] = RegClientCookie(rebuycookiename, rebuycookiedesc, CookieAccess_Protected); } } diff --git a/src/zr/zhp.inc b/src/zr/zhp.inc index 5847c1e..c03da0d 100644 --- a/src/zr/zhp.inc +++ b/src/zr/zhp.inc @@ -54,14 +54,11 @@ ZHPOnCommandsCreate() */ ZHPOnCookiesCreate() { - // Close cookie handle if it already exist. - if (g_hZHPEnabledCookie != INVALID_HANDLE) + // Create cookie handle if it doesn't exist. + if (g_hZHPEnabledCookie == INVALID_HANDLE) { - CloseHandle(g_hZHPEnabledCookie); + g_hZHPEnabledCookie = RegClientCookie(ZHP_COOKIE_ENABLED, "The toggle state of ZHP.", CookieAccess_Protected); } - - // Create ZHP cookie. - g_hZHPEnabledCookie = RegClientCookie(ZHP_COOKIE_ENABLED, "The toggle state of ZHP.", CookieAccess_Protected); } /**