提交 1e1110c4 编写于 作者: M Mikulas Patocka 提交者: Nicholas Bellinger

target: fix memory leak on XCOPY

On each processed XCOPY command, two "kmalloc-512" memory objects are
leaked. These represent two allocations of struct xcopy_pt_cmd in
target_core_xcopy.c.

The reason for the memory leak is that the cmd_kref field is not
initialized (thus, it is zero because the allocations were done with
kzalloc). When we decrement zero kref in target_put_sess_cmd, the result
is not zero, thus target_release_cmd_kref is not called.

This patch fixes the bug by moving kref initialization from
target_get_sess_cmd to transport_init_se_cmd (this function is called from
target_core_xcopy.c, so it will correctly initialize cmd_kref). It can be
easily verified that all code that calls target_get_sess_cmd also calls
transport_init_se_cmd earlier, thus moving kref_init shouldn't introduce
any new problems.
Signed-off-by: NMikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org	# 3.12+
Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
上级 07b8dae3
...@@ -1113,6 +1113,7 @@ void transport_init_se_cmd( ...@@ -1113,6 +1113,7 @@ void transport_init_se_cmd(
init_completion(&cmd->cmd_wait_comp); init_completion(&cmd->cmd_wait_comp);
init_completion(&cmd->task_stop_comp); init_completion(&cmd->task_stop_comp);
spin_lock_init(&cmd->t_state_lock); spin_lock_init(&cmd->t_state_lock);
kref_init(&cmd->cmd_kref);
cmd->transport_state = CMD_T_DEV_ACTIVE; cmd->transport_state = CMD_T_DEV_ACTIVE;
cmd->se_tfo = tfo; cmd->se_tfo = tfo;
...@@ -2357,7 +2358,6 @@ int target_get_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd, ...@@ -2357,7 +2358,6 @@ int target_get_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd,
unsigned long flags; unsigned long flags;
int ret = 0; int ret = 0;
kref_init(&se_cmd->cmd_kref);
/* /*
* Add a second kref if the fabric caller is expecting to handle * Add a second kref if the fabric caller is expecting to handle
* fabric acknowledgement that requires two target_put_sess_cmd() * fabric acknowledgement that requires two target_put_sess_cmd()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册