Fixed the handling of cache resize failures.

Previously, CacheResize() destroyed the current cache before allocating
a new one. Therefore, if CacheCreate() failed when resizing to a larger
cache, the previously used cache was also lost.

In this state, the evaluation cache becomes unusable, which could lead
to a crash when performing an evaluation from the GUI afterwards.  On my
end, after causing the resize to fail by limiting memory with ulimit -v,
it crashed with the following command:

set xgid XGID=--BBB-BA-------A---AaBhcB-:1:1:1:11:0:0:0:5:7
hint


The changes are as follows:

- In CacheResize(), CacheCreate() is first performed on a temporary newCache.
- Only when creation succeeds, the old cache is destroyed and replaced with 
newCache.
- If creation fails, it returns -1 and keeps the existing cache as is.
- In EvalCacheResize(), the return value of CacheResize() is checked, and 
cCache is not modified on failure.
- An error message is displayed if the resize fails.
  (I am not sure if this error message is appropriate as English text.)

As a result, even if expanding the cache fails due to insufficient
memory, the previously used evaluation cache can continue to be used.
In addition, since cCache also retains its previous value, this avoids
the issue where set cache 0 is mistakenly written to gnubgautorc if
settings are saved after a resize failure.

Best regards,
-- 
TAKAHASHI Kaoru

Attachment: 0001-Preserve-evaluation-cache-on-resize-failure.patch.gz
Description: application/gzip

Reply via email to