iperf: Fix data abort in iperf client.
authorEunBong Song <eunb.song@samsung.com>
Mon, 7 Aug 2017 22:18:04 +0000 (15:18 -0700)
committerEunBong Song <eunb.song@samsung.com>
Wed, 30 Aug 2017 04:16:41 +0000 (21:16 -0700)
Following test cause data abort of iperf client.
iperf -s
iperf -c 127.0.0.1
iperf -c 127.0.0.1

Data abort can happen when iperf_run_client returns negative value.
In this case, iperf calls iperf_free_test -> iperf_client_end ->
iperf_free_test. This cause data abort because test is already freed
in iperf_free_test however iperf_client_end tries to use test pointer.
And also iperf_free_test tries to free again test pointer.
This patch re-organize the process this procedure.

Change-Id: I0ad6d986cd2457648eb2a99a078b8fa3af9e3ed7
Signed-off-by: EunBong Song <eunb.song@samsung.com>
apps/examples/iperf/iperf_main.c

index 1f2d112..6d3efa1 100644 (file)
@@ -127,6 +127,7 @@ int iperf_main(int argc, char **argv)
                goto main_exit;
        }
 
+
        if (run(test) < 0) {
                printf("error - %s\n", iperf_strerror(i_errno));
                goto main_exit;
@@ -162,11 +163,16 @@ static int run(struct iperf_test *test)
                break;
        case 'c':
                if (iperf_run_client(test) < 0) {
+                       struct iperf_stream *sp;
+
+                       iperf_set_send_state(test, IPERF_DONE);
                        close(test->ctrl_sck);
-                       iperf_client_end(test);
+                       SLIST_FOREACH(sp, &test->streams, streams) {
+                               close(sp->socket);
+                       }
                        iperf_free_test(test);
                        printf("error - %s\n", iperf_strerror(i_errno));
-                       goto run_exit;
+                       exit(1);
                }
                break;
        default:
@@ -174,6 +180,5 @@ static int run(struct iperf_test *test)
                break;
        }
 
-run_exit:
        return 0;
 }