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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/errors.c b/src/errors.c
index 95c6217..f10430c 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -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();