Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix leak of dpkg cache when dpkginfo_init is called multiple times
In the dpkginfo probe, the dpkg cache was allocated in dpkginfo_init. However, dpkginfo_init can be called multiple times, leading the cgCache pointer to be overridden and leaking the dpkg cache. There are usually two dpkginfo probes running at the same time: CPE and OVAL. The opencache function is conditioned by the _init_done flag, however, this flag was never set, so opencache was always called. This change sets _init_done to 1 after opencache has been called, and allocate the dpkg cache only when _init_done is 0. Concurrent access to the cgCache static variable is now protected by a statically initialized mutex in dpkginfo_probe.c. We chose to keep cgCache as a static variable, because allocating cgCache for every thread has big performance impact. Also, calling new/delete revealed memory leaks in libapt. Consequently, cgCache is initialized once and never freed. The call to the cgCache->ReadOnlyOpen method is now done in the dpkginfo_get_by_name function, so the dpkg cache is always up to date. The cgCache->Close method is still called in dpkginfo_ini. This change also removes the unused dpkg_mmap static variable in dpkginfo-helper.cxx.
- Loading branch information