Repository navigation
fix(sql): stop the group color list from growing on every reload - #42
Merged
Merged
Conversation
- OnSQLSelect_Color reset nothing and had no bound: every sm_admins_config_mode change appended the sb_srvgroups rows again until the 255-entry array overflowed. Reset it and stop at the max. - Reuse the open connection instead of reconnecting on each cvar change, ignore a second connect while one is in flight, close a non-MySQL handle, retry a failed connect after 30 seconds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WareZ57
approved these changes
Oct 28, 2026
WareZ57
left a comment
There was a problem hiding this comment.
Checked this against master (merges cleanly, CI green) and compiled with spcomp 1.12.0.7259 + MultiColors, no warnings.
OnSQLSelect_Colornow resetsg_iColorListSizeand stops atCOLOR_LIST_MAX_LENGTH(AdvancedAdminList.sp:229-235). That fixes both the duplicate entries on everysm_admins_config_modchange and the out-of-bounds write with more than 255 groups. Callbacks run one at a time on the main thread, so two overlapping SELECTs (toggling the cvar quickly) just rebuild the same list twice.- Connection handling: an existing handle is reused (
:152-156), a second call while a connect is in flight is a no-op (:159-160), and the non-MySQL handle is now deleted instead of kept (:186-191). I didn't find any path that can assigng_hDatabasetwice or leak a handle now. - The retry timer is guarded by
g_hSQLRetryTimerso it can't stack. It has noTIMER_FLAG_NO_MAPCHANGE, so it survives a map change, and it re-checks the config mode before reconnecting (:198-206). Looks right.
Unrelated to this PR and optional: switching sm_admins_config_mod to 2 (".cfg only") doesn't clear g_iColorListSize, so the SQL colors from an earlier mode 0/1 are still used as the fallback in the lookup at :534-544. Resetting g_iColorListSize = 0 in OnCvarChanged when the mode becomes 2 would make it match the cvar description. That can be a separate change.
LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OnSQLSelect_Colorappended thesb_srvgroupsrows tog_sColorListwithout resettingg_iColorListSizeand without checkingCOLOR_LIST_MAX_LENGTH(255). Eachsm_admins_config_modchange to 0 or 1 callsSQLInitialize()and adds the whole table again. That duplicates the entries scanned for everysm_admins, and after enough changes (or with more than 255 groups) it raises an "Array index out-of-bounds" error in the callback, so the colors stop loading. Now the callback resets the size first and stops at 255 rows. (AdvancedAdminList.sp)SQLInitialize()deleted and reopened the connection on every cvar change. A change made while a connect was still in flight produced two callbacks, and both assignedg_hDatabase, so the first handle leaked. Now the open connection is reused (only the colors are reloaded), and a second call while a connect is pending does nothing. When the driver is not MySQL the handle is now closed instead of being kept, unused, asg_hDatabase. A failed connect is now logged and retried after 30 s; before, colors never loaded until the plugin was reloaded. (AdvancedAdminList.sp)Not included
sourcebansentry indatabases.cfgstill callsSetFailState, as before (it is a config error, not a failed connect).Test plan
sm_admins_config_mod1 -> 2 -> 1 several times:sm_adminsshows the same colors each time, and no array-index errors appear in the logs