make valgrind understand our memory pools

Annotate pools with valgrind macros so that it detects errors in pool
usage. Typically, we wish valgrind to detect a leak when the user fails
to call proper deallocation function.

* spot/misc/fixpool.hh, spot/misc/mspool.hh: here
* configure.ac: ensure that valgrind header exists
* tests/Makefile.am, tests/core/mempool.cc, tests/core/mempool.test,
  tests/core/.gitignore: add tests to ensure valgrind accurately detects
  leaks
This commit is contained in:
Maximilien Colange 2016-12-03 11:44:14 +01:00
parent b7e77743db
commit 3fe74f1cb9
7 changed files with 234 additions and 10 deletions

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2013, 2015, 2016 Laboratoire de Recherche et
// Copyright (C) 2011, 2013, 2015, 2016, 2018 Laboratoire de Recherche et
// Developpement de l'Epita (LRDE)
//
// This file is part of Spot, a model checking library.
@ -20,10 +20,11 @@
#pragma once
#include <spot/misc/common.hh>
#include <spot/misc/hash.hh>
#include <new>
#include <cstddef>
#include <cstdlib>
#include <unordered_map>
#if SPOT_DEBUG && defined(HAVE_VALGRIND_MEMCHECK_H)
#include <valgrind/memcheck.h>
#endif
namespace spot
{
@ -69,6 +70,12 @@ namespace spot
if (f)
{
block_* first = f;
#if SPOT_DEBUG && defined(HAVE_VALGRIND_MEMCHECK_H)
VALGRIND_MALLOCLIKE_BLOCK(f, size, 0, false);
// field f->next is initialized: prevents valgrind from complaining
// about jumps depending on uninitialized memory
VALGRIND_MAKE_MEM_DEFINED(f, sizeof(block_*));
#endif
f = f->next;
return first;
}
@ -92,6 +99,9 @@ namespace spot
void* res = free_start_;
free_start_ += size;
#if SPOT_DEBUG && defined(HAVE_VALGRIND_MEMCHECK_H)
VALGRIND_MALLOCLIKE_BLOCK(res, size, 0, false);
#endif
return res;
}
@ -113,6 +123,9 @@ namespace spot
block_*& f = freelist_[size];
b->next = f;
f = b;
#if SPOT_DEBUG && defined(HAVE_VALGRIND_MEMCHECK_H)
VALGRIND_FREELIKE_BLOCK(ptr, 0);
#endif
}
private: