Make aligned allocation without posix_memalign more robust

Instead of guessing the right function to use, we malloc() 15 bytes more than
we need, and compute the aligned offset within.  The AlignedBuffer class takes
care of passing the original pointer to free().
This commit is contained in:
Keegan McAllister
2012-03-24 22:46:51 -04:00
committed by Keith Winstein
parent 0734640e14
commit 3b61581bcd
3 changed files with 27 additions and 23 deletions
+2 -1
View File
@@ -42,13 +42,14 @@ namespace Crypto {
class AlignedBuffer {
private:
size_t m_len;
void *m_allocated;
char *m_data;
public:
AlignedBuffer( size_t len, const char *data = NULL );
~AlignedBuffer() {
free( m_data );
free( m_allocated );
}
char * data( void ) const { return m_data; }