From 91fe3de621d32b0987a98429d3f4a9e414d414fc Mon Sep 17 00:00:00 2001
From: Michael Tuexen <tuexen@fh-muenster.de>
Date: Sun, 10 Jul 2016 22:15:07 +0200
Subject: [PATCH] Don't check optval when getsockopt() failed.

Don't check optval in getsockopt() when it call failed.
The value makes no sense.
While there, fix a memomry leak.
---
 gtests/net/packetdrill/run_system_call.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gtests/net/packetdrill/run_system_call.c b/gtests/net/packetdrill/run_system_call.c
index 5e298013..04624343 100644
--- a/gtests/net/packetdrill/run_system_call.c
+++ b/gtests/net/packetdrill/run_system_call.c
@@ -3456,6 +3456,7 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall,
 	live_result = getsockopt(live_fd, level, optname, live_optval, &live_optlen);
 
 	if (end_syscall(state, syscall, CHECK_EXACT, live_result, error)) {
+		free(live_optval);
 		return STATUS_ERR;
 	}
 
@@ -3466,6 +3467,11 @@ static int syscall_getsockopt(struct state *state, struct syscall_spec *syscall,
 		return STATUS_ERR;
 	}
 
+	if (live_result != 0) {
+		free(live_optval);
+		return STATUS_OK;
+	}
+
 	switch (val_expression->type) {
 	case EXPR_LINGER:
 		result = check_linger(val_expression->value.linger, live_optval, error);
-- 
GitLab