criu: parasite_prepare_threads: free memory on error path

Submitted by Mike Rapoport on Aug. 23, 2018, 3:18 p.m.

Details

Message ID 1535037489-413-1-git-send-email-rppt@linux.vnet.ibm.com
State Accepted
Series "criu: parasite_prepare_threads: free memory on error path"
Headers show

Commit Message

Mike Rapoport Aug. 23, 2018, 3:18 p.m.
Fixes cov 191305

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 criu/parasite-syscall.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index 10504ed..b9788a4 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -477,7 +477,7 @@  static int parasite_prepare_threads(struct parasite_ctl *ctl,
 
 	thread_sp = xzalloc(sizeof(*thread_sp) * item->nr_threads);
 	if (!thread_sp)
-		return -1;
+		goto free_ctls;
 
 	for (i = 0; i < item->nr_threads; i++) {
 		struct pid *tid = &item->threads[i];
@@ -489,7 +489,7 @@  static int parasite_prepare_threads(struct parasite_ctl *ctl,
 
 		thread_ctls[i] = compel_prepare_thread(ctl, tid->real);
 		if (!thread_ctls[i])
-			return -1;
+			goto free_sp;
 
 		thread_sp[i] = compel_get_thread_sp(thread_ctls[i]);
 	}
@@ -498,6 +498,12 @@  static int parasite_prepare_threads(struct parasite_ctl *ctl,
 	dmpi(item)->thread_sp = thread_sp;
 
 	return 0;
+
+free_sp:
+	xfree(thread_sp);
+free_ctls:
+	xfree(thread_ctls);
+	return -1;
 }
 
 struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,

Comments

Andrey Vagin Aug. 29, 2018, 12:39 p.m.
Applied, thanks!

On Thu, Aug 23, 2018 at 06:18:09PM +0300, Mike Rapoport wrote:
> Fixes cov 191305
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> ---
>  criu/parasite-syscall.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
> index 10504ed..b9788a4 100644
> --- a/criu/parasite-syscall.c
> +++ b/criu/parasite-syscall.c
> @@ -477,7 +477,7 @@ static int parasite_prepare_threads(struct parasite_ctl *ctl,
>  
>  	thread_sp = xzalloc(sizeof(*thread_sp) * item->nr_threads);
>  	if (!thread_sp)
> -		return -1;
> +		goto free_ctls;
>  
>  	for (i = 0; i < item->nr_threads; i++) {
>  		struct pid *tid = &item->threads[i];
> @@ -489,7 +489,7 @@ static int parasite_prepare_threads(struct parasite_ctl *ctl,
>  
>  		thread_ctls[i] = compel_prepare_thread(ctl, tid->real);
>  		if (!thread_ctls[i])
> -			return -1;
> +			goto free_sp;
>  
>  		thread_sp[i] = compel_get_thread_sp(thread_ctls[i]);
>  	}
> @@ -498,6 +498,12 @@ static int parasite_prepare_threads(struct parasite_ctl *ctl,
>  	dmpi(item)->thread_sp = thread_sp;
>  
>  	return 0;
> +
> +free_sp:
> +	xfree(thread_sp);
> +free_ctls:
> +	xfree(thread_ctls);
> +	return -1;
>  }
>  
>  struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
> -- 
> 2.7.4
>