mmap_cache: fool-proofing build_mmap_cache

Let's try to handle better the situation when build_mmap_cache is called
without mmap_cache/mmap_cache_size being reset prior to the call.

Reported by Coverity scan.

* mmap_cache.c (build_mmap_cache): Set cache_head to tcp->mmap_cache.
Reset tcp->mmap_cache_size to 0.
This commit is contained in:
Eugene Syromyatnikov 2018-05-02 20:20:38 +02:00 committed by Dmitry V. Levin
parent f08a679a1d
commit ee023f97ab

View File

@ -55,7 +55,7 @@ static void
build_mmap_cache(struct tcb *tcp)
{
FILE *fp;
struct mmap_cache_t *cache_head = NULL;
struct mmap_cache_t *cache_head = tcp->mmap_cache;
/* start with a small dynamically-allocated array and then expand it */
size_t cur_array_size = 0;
char filename[sizeof("/proc/4294967296/maps")];
@ -68,6 +68,8 @@ build_mmap_cache(struct tcb *tcp)
return;
}
tcp->mmap_cache_size = 0;
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
struct mmap_cache_t *entry;
unsigned long start_addr, end_addr, mmap_offset;