Skip to content

Instantly share code, notes, and snippets.

@alendit
Last active April 11, 2018 06:59
Show Gist options
  • Save alendit/f759bc12e03d9dd9d72cac90a6334cc5 to your computer and use it in GitHub Desktop.
Save alendit/f759bc12e03d9dd9d72cac90a6334cc5 to your computer and use it in GitHub Desktop.
BufferSlices crash
#include <arrow/buffer.h>
#include <memory>
#include <iostream>
using namespace arrow;
using namespace std;
auto main(int argc, char* argv[]) -> int {
auto pool_buffer = make_shared<PoolBuffer>(default_memory_pool());
pool_buffer->Resize(16);
cout << "Initial parent data ptr: " << static_cast<const void*>(pool_buffer->data()) << "." << endl;
cout << "Size: " << pool_buffer->capacity() << "." << endl;
string data = "asdffdas";
strcpy(reinterpret_cast<char*>(pool_buffer->mutable_data()), data.c_str());
auto slice = SliceBuffer(pool_buffer, 0, 3);
cout << "From slice: " << slice->data() << "." << endl;
// force relocate
pool_buffer->Resize(512);
cout << "New parent data ptr: " << static_cast<const void*>(pool_buffer->data()) << "." << endl;
cout << "Slice data ptr: " << static_cast<const void*>(slice->data()) << "." << endl;
cout << "Again from slice: " << slice->data() << "." << endl; // BAM, read free'd address.
cout << "Everything's fine" << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment