Fix use of results after being unmapped
diff mbox series

Message ID 1559834477-21724-1-git-send-email-ysionneau@kalray.eu
State Changes Requested
Headers show
Series
  • Fix use of results after being unmapped
Related show

Commit Message

Yann Sionneau June 6, 2019, 3:21 p.m. UTC
This fixes issue reported there: https://github.com/linux-test-project/ltp/issues/537
---
 lib/tst_test.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Cyril Hrubis June 12, 2019, 3:16 p.m. UTC | #1
Hi!
You are missing Signed-off-by: line here, see:

https://www.kernel.org/doc/html/v4.17/process/submitting-patches.html#developer-s-certificate-of-origin-1-1

> ---
>  lib/tst_test.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 95f389d..73eca58 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -138,6 +138,7 @@ static void cleanup_ipc(void)
>  	if (results) {
>  		msync((void*)results, size, MS_SYNC);
>  		munmap((void*)results, size);
> +		results = NULL;
>  	}
>  }
>  
> @@ -921,10 +922,11 @@ static void do_cleanup(void)
>  	if (tst_test->save_restore)
>  		tst_sys_conf_restore(0);
>  
> -	cleanup_ipc();
> -
>  	if (tst_test->restore_wallclock)
>  		tst_wallclock_restore();
> +
> +	cleanup_ipc();
> +	/* Do not use 'results' after cleanup_ipc(): it has been unmapped. */

Actually we can remove this comment since after setting results to NULL
we will not crash anymore.

Patch
diff mbox series

diff --git a/lib/tst_test.c b/lib/tst_test.c
index 95f389d..73eca58 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -138,6 +138,7 @@  static void cleanup_ipc(void)
 	if (results) {
 		msync((void*)results, size, MS_SYNC);
 		munmap((void*)results, size);
+		results = NULL;
 	}
 }
 
@@ -921,10 +922,11 @@  static void do_cleanup(void)
 	if (tst_test->save_restore)
 		tst_sys_conf_restore(0);
 
-	cleanup_ipc();
-
 	if (tst_test->restore_wallclock)
 		tst_wallclock_restore();
+
+	cleanup_ipc();
+	/* Do not use 'results' after cleanup_ipc(): it has been unmapped. */
 }
 
 static void run_tests(void)