sched-deps: Clear dependency caches before freeing them
Fixes memory leaks in sched-deps by ensuring dependency cache bitmaps are cleared before cache arrays are freed.
This commit corrects a memory leak in the sched-deps component by ensuring that dependency cache bitmaps are properly cleared before the associated cache arrays are freed. Previously, sched_deps_finish reset cache_size prematurely, causing the cleanup loop to iterate zero times. This resulted in the cache arrays being freed without their bitmap elements being returned to the obstack. The fix moves the cache_size reset to after the cleanup loop, guaranteeing that all allocated memory is reclaimed.
In Details
In sched-deps, dependency caches are used for efficient lookup. The sched_deps_finish function is responsible for cleaning up these caches. However, it incorrectly reset cache_size before iterating through the cache bitmaps for cleanup. This caused the bitmap elements to be leaked when the cache arrays were subsequently freed. By moving the reset of cache_size to after the bitmap clearing loop, this patch ensures that all allocated cache memory is properly returned to the obstack.
- sched-deps
- A component within the GCC compiler that analyzes and manages dependencies between instructions to optimize instruction scheduling.
- dependency cache
- A data structure used within
sched-depsto store and quickly retrieve information about dependencies between instructions. - obstack
- A memory allocation system that allows for efficient allocation and deallocation of temporary objects, often used in compilers for intermediate data structures.