diff options
author | Olivier Fourdan <ofourdan@redhat.com> | 2022-07-12 14:44:48 +0200 |
---|---|---|
committer | Olivier Fourdan <ofourdan@redhat.com> | 2022-07-27 17:09:29 +0200 |
commit | 2efa6d659508346358a1ef27b2393e18843f66a3 (patch) | |
tree | 456afa5670ffc10388190a64ca27898a6b420d2d /dix | |
parent | 24d7d93ff2dc0ef4a0517734f0aae01cd7d57bba (diff) | |
download | xserver-2efa6d659508346358a1ef27b2393e18843f66a3.tar.gz |
dix: Fix overzealous caching of ResourceClientBits()
Commit c7311654 cached the value of ResourceClientBits(), but that value
depends on the `MaxClients` value set either from the command line or
from the configuration file.
For the latter, a call to ResourceClientBits() is issued before the
configuration file is read, meaning that the cached value is from the
default, not from the maximum number of clients set in the configuration
file.
That obviously causes all sort of issues, including memory corruption
and crashes of the Xserver when reaching the default limit value.
To avoid that issue, also keep the LimitClient value, and recompute the
ilog2() value if that changes, as on startup when the value is set from
the the xorg.conf ServerFlags section.
v2: Drop the `cache == 0` test
Rename cache vars
Fixes: c7311654 - dix: cache ResourceClientBits() value
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1310
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'dix')
-rw-r--r-- | dix/resource.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/dix/resource.c b/dix/resource.c index 6c0be2e04..055e6934e 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -620,12 +620,15 @@ ilog2(int val) unsigned int ResourceClientBits(void) { - static unsigned int cached = 0; + static unsigned int cache_ilog2 = 0; + static unsigned int cache_limit = 0; - if (cached == 0) - cached = ilog2(LimitClients); + if (LimitClients != cache_limit) { + cache_limit = LimitClients; + cache_ilog2 = ilog2(LimitClients); + } - return cached; + return cache_ilog2; } /***************** |