target: fix memory leak on XCOPY
authorMikulas Patocka <mpatocka@redhat.com>
Sat, 17 May 2014 10:49:22 +0000 (06:49 -0400)
committerJiri Slaby <jslaby@suse.cz>
Mon, 9 Jun 2014 13:53:46 +0000 (15:53 +0200)
commitabcea86934d7924502425415276fe9668601acab
tree1b608b41928467e44edf7ca99daabf6438c0fe56
parent1b8b4d6d14a3704e221b0e580d93650903ab7038
target: fix memory leak on XCOPY

commit 1e1110c43b1cda9fe77fc4a04835e460550e6b3c upstream.

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>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
drivers/target/target_core_transport.c