aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/compression/comp_util.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-11-18 13:42:36 +0000
committerlloyd <[email protected]>2014-11-18 13:42:36 +0000
commitdec2e0d9e493b53c48ca26b47028ab309d3cc586 (patch)
tree2242f756ece5e1a9cc728dc208c154e694314d5a /src/lib/compression/comp_util.cpp
parentb5e2a1ce3044084e43ff523f148b0cc8e95ce283 (diff)
Convert compression filters to in-place transforms and refactor
to minimize the amount of logic needed in the files specific to each library.
Diffstat (limited to 'src/lib/compression/comp_util.cpp')
-rw-r--r--src/lib/compression/comp_util.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/compression/comp_util.cpp b/src/lib/compression/comp_util.cpp
new file mode 100644
index 000000000..7fca1852d
--- /dev/null
+++ b/src/lib/compression/comp_util.cpp
@@ -0,0 +1,34 @@
+/*
+* Allocation Tracker
+* (C) 2014 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/internal/comp_util.h>
+#include <cstring>
+#include <cstdlib>
+
+namespace Botan {
+
+void* Compression_Alloc_Info::do_malloc(size_t n, size_t size)
+ {
+ const size_t total_sz = n * size;
+
+ void* ptr = std::malloc(total_sz);
+ m_current_allocs[ptr] = total_sz;
+ return ptr;
+ }
+
+void Compression_Alloc_Info::do_free(void* ptr)
+ {
+ auto i = m_current_allocs.find(ptr);
+ if(i == m_current_allocs.end())
+ throw std::runtime_error("Compression_Alloc_Info::free got pointer not allocated by us");
+
+ std::memset(ptr, 0, i->second);
+ std::free(ptr);
+ m_current_allocs.erase(i);
+ }
+
+}