All of lore.kernel.org
 help / color / mirror / Atom feed
* [Ocfs2-devel] [patch 1/4] ocfs2: fix a couple of memory leaks at o2hb_map_slot_data()
@ 2012-08-22  9:38 Jeff Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Liu @ 2012-08-22  9:38 UTC (permalink / raw)
  To: ocfs2-devel

This patch can fix a couple of potential memory leaks at o2hb_map_slot_data().

Signed-off-by: Jie Liu <jeff.liu@oracle.com>

---
 fs/ocfs2/cluster/heartbeat.c |   33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index a4e855e..1b6ce53 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1638,7 +1638,7 @@ static void o2hb_init_region_params(struct o2hb_region *reg)
 
 static int o2hb_map_slot_data(struct o2hb_region *reg)
 {
-	int i, j;
+	int ret = 0, i, j;
 	unsigned int last_slot;
 	unsigned int spp = reg->hr_slots_per_page;
 	struct page *page;
@@ -1654,8 +1654,8 @@ static int o2hb_map_slot_data(struct o2hb_region *reg)
 	reg->hr_slots = kcalloc(reg->hr_blocks,
 				sizeof(struct o2hb_disk_slot), GFP_KERNEL);
 	if (reg->hr_slots == NULL) {
-		mlog_errno(-ENOMEM);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto free;
 	}
 
 	for(i = 0; i < reg->hr_blocks; i++) {
@@ -1673,15 +1673,15 @@ static int o2hb_map_slot_data(struct o2hb_region *reg)
 	reg->hr_slot_data = kcalloc(reg->hr_num_pages, sizeof(struct page *),
 				    GFP_KERNEL);
 	if (!reg->hr_slot_data) {
-		mlog_errno(-ENOMEM);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto free;
 	}
 
 	for(i = 0; i < reg->hr_num_pages; i++) {
 		page = alloc_page(GFP_KERNEL);
 		if (!page) {
-			mlog_errno(-ENOMEM);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto free;
 		}
 
 		reg->hr_slot_data[i] = page;
@@ -1701,7 +1701,24 @@ static int o2hb_map_slot_data(struct o2hb_region *reg)
 		}
 	}
 
-	return 0;
+	return ret;
+
+free:
+	mlog_errno(ret);
+
+	kfree(reg->hr_tmp_block);
+	kfree(reg->hr_slots);
+
+	if (reg->hr_slot_data) {
+		for (i = 0; i < reg->hr_num_pages; i++) {
+			page = reg->hr_slot_data[i];
+			if (page)
+				__free_page(reg->hr_slot_data[i]);
+		}
+		kfree(reg->hr_slot_data);
+	}
+
+	return ret;
 }
 
 /* Read in all the slots available and populate the tracking
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Ocfs2-devel] [patch 1/4] ocfs2: fix a couple of memory leaks at o2hb_map_slot_data()
@ 2013-05-27 11:32 Joseph Qi
  2013-05-27 11:56 ` Jeff Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Qi @ 2013-05-27 11:32 UTC (permalink / raw)
  To: ocfs2-devel

These memory will be freed in o2hb_region_release. If we free them here,
then it will lead to double freed issue.

> This patch can fix a couple of potential memory leaks at
> o2hb_map_slot_data().
> 
> Signed-off-by: Jie Liu <jeff.liu@oracle.com>
> 
> ---
>  fs/ocfs2/cluster/heartbeat.c |   33 +++++++++++++++++++++++++--------
>  1 files changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
> index a4e855e..1b6ce53 100644
> --- a/fs/ocfs2/cluster/heartbeat.c
> +++ b/fs/ocfs2/cluster/heartbeat.c
> @@ -1638,7 +1638,7 @@ static void o2hb_init_region_params(struct
> o2hb_region *reg)
> 
>  static int o2hb_map_slot_data(struct o2hb_region *reg)
>  {
> -	int i, j;
> +	int ret = 0, i, j;
>  	unsigned int last_slot;
>  	unsigned int spp = reg->hr_slots_per_page;
>  	struct page *page;
> @@ -1654,8 +1654,8 @@ static int o2hb_map_slot_data(struct o2hb_region *reg)
>  	reg->hr_slots = kcalloc(reg->hr_blocks,
>  				sizeof(struct o2hb_disk_slot), GFP_KERNEL);
>  	if (reg->hr_slots == NULL) {
> -		mlog_errno(-ENOMEM);
> -		return -ENOMEM;
> +		ret = -ENOMEM;
> +		goto free;
>  	}
> 
>  	for(i = 0; i < reg->hr_blocks; i++) {
> @@ -1673,15 +1673,15 @@ static int o2hb_map_slot_data(struct o2hb_region
> *reg)
>  	reg->hr_slot_data = kcalloc(reg->hr_num_pages, sizeof(struct page *),
>  				    GFP_KERNEL);
>  	if (!reg->hr_slot_data) {
> -		mlog_errno(-ENOMEM);
> -		return -ENOMEM;
> +		ret = -ENOMEM;
> +		goto free;
>  	}
> 
>  	for(i = 0; i < reg->hr_num_pages; i++) {
>  		page = alloc_page(GFP_KERNEL);
>  		if (!page) {
> -			mlog_errno(-ENOMEM);
> -			return -ENOMEM;
> +			ret = -ENOMEM;
> +			goto free;
>  		}
> 
>  		reg->hr_slot_data[i] = page;
> @@ -1701,7 +1701,24 @@ static int o2hb_map_slot_data(struct o2hb_region
> *reg)
>  		}
>  	}
> 
> -	return 0;
> +	return ret;
> +
> +free:
> +	mlog_errno(ret);
> +
> +	kfree(reg->hr_tmp_block);
> +	kfree(reg->hr_slots);
> +
> +	if (reg->hr_slot_data) {
> +		for (i = 0; i < reg->hr_num_pages; i++) {
> +			page = reg->hr_slot_data[i];
> +			if (page)
> +				__free_page(reg->hr_slot_data[i]);
> +		}
> +		kfree(reg->hr_slot_data);
> +	}
> +
> +	return ret;
>  }
> 
>  /* Read in all the slots available and populate the tracking
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Ocfs2-devel] [patch 1/4] ocfs2: fix a couple of memory leaks at o2hb_map_slot_data()
  2013-05-27 11:32 Joseph Qi
@ 2013-05-27 11:56 ` Jeff Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Liu @ 2013-05-27 11:56 UTC (permalink / raw)
  To: ocfs2-devel

On 05/27/2013 07:32 PM, Joseph Qi wrote:

> These memory will be freed in o2hb_region_release. If we free them here,
> then it will lead to double freed issue.

You're right. Thanks for letting me know about this.

-Jeff

> 
>> This patch can fix a couple of potential memory leaks at
>> o2hb_map_slot_data().
>>
>> Signed-off-by: Jie Liu <jeff.liu@oracle.com>
>>
>> ---
>>  fs/ocfs2/cluster/heartbeat.c |   33 +++++++++++++++++++++++++--------
>>  1 files changed, 25 insertions(+), 8 deletions(-)
>>
>> diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
>> index a4e855e..1b6ce53 100644
>> --- a/fs/ocfs2/cluster/heartbeat.c
>> +++ b/fs/ocfs2/cluster/heartbeat.c
>> @@ -1638,7 +1638,7 @@ static void o2hb_init_region_params(struct
>> o2hb_region *reg)
>>
>>  static int o2hb_map_slot_data(struct o2hb_region *reg)
>>  {
>> -	int i, j;
>> +	int ret = 0, i, j;
>>  	unsigned int last_slot;
>>  	unsigned int spp = reg->hr_slots_per_page;
>>  	struct page *page;
>> @@ -1654,8 +1654,8 @@ static int o2hb_map_slot_data(struct o2hb_region *reg)
>>  	reg->hr_slots = kcalloc(reg->hr_blocks,
>>  				sizeof(struct o2hb_disk_slot), GFP_KERNEL);
>>  	if (reg->hr_slots == NULL) {
>> -		mlog_errno(-ENOMEM);
>> -		return -ENOMEM;
>> +		ret = -ENOMEM;
>> +		goto free;
>>  	}
>>
>>  	for(i = 0; i < reg->hr_blocks; i++) {
>> @@ -1673,15 +1673,15 @@ static int o2hb_map_slot_data(struct o2hb_region
>> *reg)
>>  	reg->hr_slot_data = kcalloc(reg->hr_num_pages, sizeof(struct page *),
>>  				    GFP_KERNEL);
>>  	if (!reg->hr_slot_data) {
>> -		mlog_errno(-ENOMEM);
>> -		return -ENOMEM;
>> +		ret = -ENOMEM;
>> +		goto free;
>>  	}
>>
>>  	for(i = 0; i < reg->hr_num_pages; i++) {
>>  		page = alloc_page(GFP_KERNEL);
>>  		if (!page) {
>> -			mlog_errno(-ENOMEM);
>> -			return -ENOMEM;
>> +			ret = -ENOMEM;
>> +			goto free;
>>  		}
>>
>>  		reg->hr_slot_data[i] = page;
>> @@ -1701,7 +1701,24 @@ static int o2hb_map_slot_data(struct o2hb_region
>> *reg)
>>  		}
>>  	}
>>
>> -	return 0;
>> +	return ret;
>> +
>> +free:
>> +	mlog_errno(ret);
>> +
>> +	kfree(reg->hr_tmp_block);
>> +	kfree(reg->hr_slots);
>> +
>> +	if (reg->hr_slot_data) {
>> +		for (i = 0; i < reg->hr_num_pages; i++) {
>> +			page = reg->hr_slot_data[i];
>> +			if (page)
>> +				__free_page(reg->hr_slot_data[i]);
>> +		}
>> +		kfree(reg->hr_slot_data);
>> +	}
>> +
>> +	return ret;
>>  }
>>
>>  /* Read in all the slots available and populate the tracking
>>
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-05-27 11:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-22  9:38 [Ocfs2-devel] [patch 1/4] ocfs2: fix a couple of memory leaks at o2hb_map_slot_data() Jeff Liu
  -- strict thread matches above, loose matches on Subject: below --
2013-05-27 11:32 Joseph Qi
2013-05-27 11:56 ` Jeff Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.