[SCSI] target: Fix match_strdup() memory leaks
match_strdup() dynamically allocates memory and it is the responsabillity of the caller to free that memory. The following three cases: drivers/target/target_core_file.c:fd_set_configfs_dev_params() drivers/target/target_core_iblock.c:iblock_set_configfs_dev_params() drivers/target/target_core_configfs.c:target_core_dev_pr_store_attr_res_aptpl_metadata() should be kfree()'ing the allocated memory once it is no longer needed. It also makes sure to return -ENOMEM if the memory allocation in match_strdup() should fail. For target_core_configfs.c, this patch adds kfree()'s around Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid, Opt_sa_res_key, Opt_target_fabric, and Opt_target_node for the Persistent Reservations Activate Persistence across Target Power Loss (APTPL=1) token parsing. Signed-off-by: Jesper Juhl <jj@chaosbits.net> Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
This commit is contained in:
committed by
James Bottomley
parent
8fc1858a42
commit
6d1802539d
@@ -536,15 +536,26 @@ static ssize_t fd_set_configfs_dev_params(
|
||||
token = match_token(ptr, tokens, args);
|
||||
switch (token) {
|
||||
case Opt_fd_dev_name:
|
||||
arg_p = match_strdup(&args[0]);
|
||||
if (!arg_p) {
|
||||
ret = -ENOMEM;
|
||||
break;
|
||||
}
|
||||
snprintf(fd_dev->fd_dev_name, FD_MAX_DEV_NAME,
|
||||
"%s", match_strdup(&args[0]));
|
||||
"%s", arg_p);
|
||||
kfree(arg_p);
|
||||
printk(KERN_INFO "FILEIO: Referencing Path: %s\n",
|
||||
fd_dev->fd_dev_name);
|
||||
fd_dev->fbd_flags |= FBDF_HAS_PATH;
|
||||
break;
|
||||
case Opt_fd_dev_size:
|
||||
arg_p = match_strdup(&args[0]);
|
||||
if (!arg_p) {
|
||||
ret = -ENOMEM;
|
||||
break;
|
||||
}
|
||||
ret = strict_strtoull(arg_p, 0, &fd_dev->fd_dev_size);
|
||||
kfree(arg_p);
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR "strict_strtoull() failed for"
|
||||
" fd_dev_size=\n");
|
||||
|
Reference in New Issue
Block a user