Make giterr_restore aware of g_git_oom_error

Allow restoring a previously captured oom error, by
detecting when the captured message pointer points to the
static oom error message.  This means there is no need
to strdup the message in giterr_detach.
This commit is contained in:
Michael Procter 2015-07-27 10:10:18 +01:00
parent 25dbcf3499
commit 0fcfb60dc4

View File

@ -125,14 +125,12 @@ static int giterr_detach(git_error *cpy)
if (!error)
return -1;
if (error == &g_git_oom_error) {
cpy->message = git__strdup(error->message);
} else {
cpy->message = error->message;
error->message = NULL;
}
cpy->message = error->message;
cpy->klass = error->klass;
if (error != &g_git_oom_error) {
error->message = NULL;
}
giterr_clear();
return 0;
@ -153,8 +151,13 @@ int giterr_capture(git_error_state *state, int error_code)
int giterr_restore(git_error_state *state)
{
if (state && state->error_code && state->error_msg.message)
set_error(state->error_msg.klass, state->error_msg.message);
if (state && state->error_code && state->error_msg.message) {
if (state->error_msg.message == g_git_oom_error.message) {
giterr_set_oom();
} else {
set_error(state->error_msg.klass, state->error_msg.message);
}
}
else
giterr_clear();