Suppose I have some C++ code which has a try-catch block in which the catch
part will trigger a long jump:
#include <stdexcept>
#include <stdio.h>
#include <setjmp.h>
void my_fun()
{
jmp_buf jump_buffer;
if (setjmp(jump_buffer))
return;
try {
std::string message;
message.resize(100);
snprintf(&message[0], 100, "error code %d\n", 3);
throw std::runtime_error(message);
}
catch (std::runtime_error &e) {
longjmp(jump_buffer, 1);
}
}
Since the std::runtime_error
object was allocated dynamically somewhere, will it leak the memory that was allocated for it or for the string?