…apServer#7614)
msConnPoolRegister() incremented connectionMax before the realloc() that
was meant to deliver the new capacity, and did not restore it when the
allocation failed. After one failed grow the recorded capacity stayed 10
entries ahead of the real one, and because the guard was an equality test
the growth path never ran again, so the following registrations each wrote
a whole connectionObj past the end of the array.
Move the increment after the successful realloc and make the guard >= so
that a count which has passed the capacity still grows the array.
This completes f4286d6, which stopped a failed realloc from leaking and
from nulling connections, but left the connectionMax desync in place. That
turned what used to be a near-NULL crash into a silent heap overflow.
What does this PR do?
This moves the increment after the successful realloc and changes the guard to >=.
It completes f4286d6: that commit stopped the failed realloc from leaking and from nulling connections, but left the connectionMax desync in place, which turned the old near-NULL crash into a silent heap overflow.
What are related issues/pull requests?
Fixes #7614
Tasklist
I could not find a way to write this one as an msautotest case. Triggering it needs the pool array's realloc() to fail, and the suite has no way to inject an allocation failure; msConnPoolRegister() is also not exposed to MapScript, and its callers are the database drivers, so reaching it from the test suite would need a live backend as well. The C reproducer in the issue covers it instead. Glad to add a test if you see an angle I missed.