Commit 0fcfb60dc4f5e6cfd91c902d844f5d8665a5c1a7

Michael Procter 2015-07-27T10:10:18

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.

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();