]> git.baikalelectronics.ru Git - kernel.git/commit
target: fix memory leak on XCOPY
authorMikulas Patocka <mpatocka@redhat.com>
Sat, 17 May 2014 10:49:22 +0000 (06:49 -0400)
committerNicholas Bellinger <nab@linux-iscsi.org>
Sat, 17 May 2014 22:49:40 +0000 (15:49 -0700)
commitdc9721c642091354311126b44ecd8427041a4d3d
tree23aa84128267ab35f2f0c44d33e62b77968ac698
parent9ac26b8407828eedf5a9c22d655c476d0da11964
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: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org # 3.12+
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_transport.c