• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 13210394651

08 Feb 2025 12:33AM UTC coverage: 91.656% (-0.006%) from 91.662%
13210394651

push

github

web-flow
Merge pull request #4642 from randombit/jack/target-info-header

Add internal target_info.h header

94837 of 103471 relevant lines covered (91.66%)

11243945.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.35
/src/lib/utils/allocator.cpp
1
/*
2
* (C) 2017,2023 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include <botan/allocator.h>
8

9
#include <botan/mem_ops.h>
10
#include <botan/internal/int_utils.h>
11
#include <botan/internal/target_info.h>
12
#include <cstdlib>
13
#include <new>
14

15
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
16
   #include <botan/internal/locking_allocator.h>
17
#endif
18

19
namespace Botan {
20

21
BOTAN_MALLOC_FN void* allocate_memory(size_t elems, size_t elem_size) {
160,327,534✔
22
   if(elems == 0 || elem_size == 0) {
160,327,534✔
23
      return nullptr;
24
   }
25

26
   // Some calloc implementations do not check for overflow (?!?)
27
   if(!checked_mul(elems, elem_size).has_value()) {
320,655,068✔
28
      throw std::bad_alloc();
×
29
   }
30

31
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
32
   if(void* p = mlock_allocator::instance().allocate(elems, elem_size)) {
160,327,534✔
33
      return p;
34
   }
35
#endif
36

37
#if defined(BOTAN_TARGET_OS_HAS_ALLOC_CONCEAL)
38
   void* ptr = ::calloc_conceal(elems, elem_size);
39
#else
40
   void* ptr = std::calloc(elems, elem_size);  // NOLINT(*-no-malloc)
30,597,632✔
41
#endif
42
   if(!ptr) {
30,597,632✔
43
      [[unlikely]] throw std::bad_alloc();
×
44
   }
45
   return ptr;
46
}
47

48
void deallocate_memory(void* p, size_t elems, size_t elem_size) {
160,327,076✔
49
   if(p == nullptr) {
160,327,076✔
50
      [[unlikely]] return;
×
51
   }
52

53
   secure_scrub_memory(p, elems * elem_size);
160,327,076✔
54

55
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
56
   if(mlock_allocator::instance().deallocate(p, elems, elem_size)) {
160,327,076✔
57
      return;
58
   }
59
#endif
60

61
   std::free(p);  // NOLINT(*-no-malloc)
30,597,442✔
62
}
63

64
void initialize_allocator() {
406✔
65
#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
66
   mlock_allocator::instance();
406✔
67
#endif
68
}
406✔
69

70
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc