Created
April 11, 2018 11:39
-
-
Save alendit/00e4bd5f0e8a79e8ff9ebd86995f3905 to your computer and use it in GitHub Desktop.
MutableSlices failing after dealloc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <arrow/buffer.h> | |
#include <memory> | |
#include <iostream> | |
using namespace arrow; | |
using namespace std; | |
auto main(int argc, char* argv[]) -> int { | |
int64_t size = 16; | |
auto* memory = static_cast<uint8_t*>(malloc(size)); | |
shared_ptr<Buffer> mutable_slice; | |
{ | |
// owns the memory, but just by convention | |
auto mutable_buffer = make_shared<MutableBuffer>(memory, size); | |
strcpy(reinterpret_cast<char*>(mutable_buffer->mutable_data()), "asdf"); | |
// doesn't own the memory nor has any insight in the parent | |
mutable_slice = SliceMutableBuffer(mutable_buffer, 0, 2); | |
cout << mutable_slice->data() << endl; | |
// we since we own the memory we release it beforehand | |
free(memory); | |
} | |
// no way of knowing if it is safe to do | |
cout << mutable_slice->data() << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment