| Kea 3.0.2-git

newhook.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <stdlib.h>
10
11#include <new>
12#include <stdexcept>
13
14#include <util/unittests/newhook.h>
15
16#ifdef ENABLE_CUSTOM_OPERATOR_NEW
17 void*
18 operator new(size_t size) throw(std::bad_alloc) {
19 if (isc::util::unittests::force_throw_on_new &&
20 size == isc::util::unittests::throw_size_on_new) {
21 throw std::bad_alloc();
22 }
23 void* p = malloc(size);
24 if (p == NULL) {
25 throw std::bad_alloc();
26 }
27 return (p);
28}
29
30 void
31 operator delete(void* p) throw() {
32 if (p != NULL) {
33 free(p);
34 }
35}
36#endif
37
38 namespace isc {
39 namespace util {
40 namespace unittests {
41 bool force_throw_on_new = false;
42 size_t throw_size_on_new = 0;
43}
44}
45}
isc::util::unittests
Definition check_valgrind.cc:11
isc::util::unittests::throw_size_on_new
size_t throw_size_on_new
The allocation size that triggers an exception in the special operator new.
Definition newhook.cc:42
isc::util::unittests::force_throw_on_new
bool force_throw_on_new
Switch to enable the use of special operator new.
Definition newhook.cc:41
isc::util
Definition time_utils.cc:43
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
newhook.h
Enable the use of special operator new that throws for testing.