Skip to content

Instantly share code, notes, and snippets.

@FlyingJester
Created August 1, 2014 20:52
Show Gist options
  • Select an option

  • Save FlyingJester/763a61d9aeed88f238aa to your computer and use it in GitHub Desktop.

Select an option

Save FlyingJester/763a61d9aeed88f238aa to your computer and use it in GitHub Desktop.
setjmp/longjmp Causing leaks!
//g++ -std=c++11 setjmp_unique_ptr.cpp -o demo
#include <cstdio>
#include <memory>
#include <csetjmp>
struct Test {
Test(){
std::fputs("Created Test.\n", stdout);
}
~Test(){
std::fputs("Destroyed Test.\n", stdout);
}
};
int main(){
std::jmp_buf f;
if(setjmp(f)){return 0;}
std::unique_ptr<Test> TestHolder(new Test());
longjmp(f, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment