diff mbox

[1/4] btrfs-progs: Fix memory leak in write_raid56_with_parity

Message ID 20161024024335.6770-1-quwenruo@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Qu Wenruo Oct. 24, 2016, 2:43 a.m. UTC
Ebs and pointers are allocated, but if any of the allocation failed, we
should free the allocated memory.

Reported-by: David Sterba <dsterba@suse.cz>
Resolves-Coverity-CID: 1296749
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 volumes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Qu Wenruo Oct. 24, 2016, 3:04 a.m. UTC | #1
At 10/24/2016 10:43 AM, Qu Wenruo wrote:
> Ebs and pointers are allocated, but if any of the allocation failed, we
> should free the allocated memory.
>
> Reported-by: David Sterba <dsterba@suse.cz>
> Resolves-Coverity-CID: 1296749

Sorry, wrong CID here,
Correct ones are:
Resolves-Coverity-CID: 1374101
Resolves-Coverity-CID: 1374100


> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> ---
>  volumes.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/volumes.c b/volumes.c
> index a7abd92..f687b0d 100644
> --- a/volumes.c
> +++ b/volumes.c
> @@ -2120,8 +2120,11 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
>
>  	ebs = malloc(sizeof(*ebs) * multi->num_stripes);
>  	pointers = malloc(sizeof(*pointers) * multi->num_stripes);
> -	if (!ebs || !pointers)
> +	if (!ebs || !pointers) {
> +		free(ebs);
> +		free(pointers);
>  		return -ENOMEM;
> +	}
>
>  	if (stripe_len > alloc_size)
>  		alloc_size = stripe_len;
>


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba Oct. 25, 2016, 2:35 p.m. UTC | #2
On Mon, Oct 24, 2016 at 10:43:32AM +0800, Qu Wenruo wrote:
> Ebs and pointers are allocated, but if any of the allocation failed, we
> should free the allocated memory.
> 
> Reported-by: David Sterba <dsterba@suse.cz>
> Resolves-Coverity-CID: 1296749
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

1-4 applied, thanks. Please don't put my reported-by there.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/volumes.c b/volumes.c
index a7abd92..f687b0d 100644
--- a/volumes.c
+++ b/volumes.c
@@ -2120,8 +2120,11 @@  int write_raid56_with_parity(struct btrfs_fs_info *info,
 
 	ebs = malloc(sizeof(*ebs) * multi->num_stripes);
 	pointers = malloc(sizeof(*pointers) * multi->num_stripes);
-	if (!ebs || !pointers)
+	if (!ebs || !pointers) {
+		free(ebs);
+		free(pointers);
 		return -ENOMEM;
+	}
 
 	if (stripe_len > alloc_size)
 		alloc_size = stripe_len;