lkml.org 
[lkml]   [2011]   [Jul]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] Fix leak in drivers/target/iscsi/iscsi_target_parameters.c::iscsi_copy_param_list()
From
Date
On Mon, 2011-08-01 at 00:28 +0200, Jesper Juhl wrote:
> We leak memory if the allocations for 'new_param->name' or 'new_param->value' fail.
> We also do a lot of variable assignments that are completely pointless
> if the allocations fail.
> So, let's move the allocations before the assignments and also make
> sure that we free whatever was allocated to one if the allocation for
> another fails.

> diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
[]
> + new_param->name = kmalloc(strlen(param->name) + 1, GFP_KERNEL);
> + new_param->value = kmalloc(strlen(param->value) + 1, GFP_KERNEL);
[]
> memcpy(new_param->name, param->name, strlen(param->name));
> new_param->name[strlen(param->name)] = '\0';
> memcpy(new_param->value, param->value, strlen(param->value));

kstrdup



\
 
 \ /
  Last update: 2011-08-01 00:47    [W:0.363 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site