libceph: fix a memory leak in handle_watch_notify
PATCH 1/1 libceph: fix a memory leak in handle_watch_notify
From: Li RongQing <[email protected]>
event_work should be freed when adding it to queue failed
--- net/ceph/osd_client.c | 1 + 1 file changed, 1 insertion(+)
net/ceph/osd_client.c +1 -0
@@ -2323,6 +2323,7 @@ static void handle_watch_notify(struct ceph_osd_client *osdc, event_work->opcode = opcode;if (!queue_work (osdc->notify_wq, &event_work->work)) {dout ("WARNING: failed to queue notify event work\n" ); +kfree (event_work); goto done_err; } }
Signature · 1 line
1.7.10.4
Quoted 5 lines · On 09/10/2014 07:20 PM, [email protected] wrote:
From: Li RongQing <[email protected]>
event_workshould be freed when adding it to queue failedSigned-off-by Li RongQing <[email protected]>
Looks good.
Quoted 17 lines
--- net/ceph/osd_client.c | 1 + 1 file changed, 1 insertion(+)net/ceph/osd_client.c +1
-0@@ -2323,6 +2323,7 @@ static void handle_watch_notify(struct ceph_osd_client *osdc, event_work->opcode = opcode;if (!queue_work (osdc->notify_wq, &event_work->work)) {dout ("WARNING: failed to queue notify event work\n" ); +kfree (event_work); goto done_err; } }
Quoted 4 lines · Alex Elder
Quoted 3 lines · On 09/10/2014 07:20 PM, [email protected] wrote:
From: Li RongQing <[email protected]>
Quoted 8 lines
Quoted 3 lines
event_workshould be freed when adding it to queue failedSigned-off-by Li RongQing <[email protected]>Looks good.
Reviewed-by Alex Elder <[email protected]>
Hmm, queue_work() returns %false if @work was already on a queue, %true otherwise, so this seems bogus to me. I'd go with something like this (mangled).
From c0711eee447b199b1c2193460fce8c9d958f23f4 Mon Sep 17 00:00:00 2001
From: Ilya Dryomov <[email protected]>
Date: Thu, 11 Sep 2014 12:18:53 +0400
Subject: [PATCH] libceph: don't try checking queue_work() return value
queue_work() doesn't "fail to queue", it returns false if work was already on a queue, which can't happen here since we allocate event_work right before we queue it. So don't bother at all.
--- net/ceph/osd_client.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
net/ceph/osd_client.c +0 -0
@@ -2355,26 +2355,21 @@ static void handle_watch_notify(struct
ceph_osd_client *osdc,
if (event) {
event_work = kmalloc(sizeof(*event_work), GFP_NOIO);
if (!event_work) {
- dout("ERROR: could not allocate event_work\n");
- goto done_err;
+ pr_err("couldn't allocate event_work\n");
+ ceph_osdc_put_event(event);
+ return;
}
INIT_WORK(&event_work->work, do_event_work);
event_work->event = event;
event_work->ver = ver;
event_work->notify_id = notify_id;
event_work->opcode = opcode;- if (!queue_work(osdc->notify_wq, &event_work->work)) {
- dout("WARNING: failed to queue notify event work\n");
- goto done_err;
- }
+
+ queue_work(osdc->notify_wq, &event_work->work);
}
return;-done_err:
- ceph_osdc_put_event(event);
- return;
-
bad:
pr_err("osdc handle_watch_notify corrupt msg\n");}
Signature · 1 line
1.7.10.4
Quoted 10 lines · Ilya Dryomov
Quoted 9 lines · Alex Elder
Quoted 6 lines · On 09/10/2014 07:20 PM, [email protected] wrote:
From: Li RongQing <[email protected]>
event_workshould be freed when adding it to queue failedSigned-off-by Li RongQing <[email protected]>
Quoted 7 lines
Quoted 3 lines
Looks good.
Reviewed-by Alex Elder <[email protected]>Hmm,
queue_work()returns %false if @work was already on a queue, %true otherwise, so this seems bogus to me. I'd go with something like this (mangled).
The original change was fine. Whether it matters is another question. Your suggestion looks good as well, and on the assumption that if you choose to use it instead your "real" fix is done correctly you can use "Reviewed-by: <me>" if you like.
-Alex
Quoted 53 lines
From
c0711eee447b199b1c2193460fce8c9d958f23f4Mon Sep 17 00:00:00 2001
From: Ilya Dryomov <[email protected]>
Date: Thu, 11 Sep 2014 12:18:53 +0400
Subject: [PATCH] libceph: don't try checkingqueue_work()return value
queue_work()doesn't "fail to queue", it returns false if work was already on a queue, which can't happen here since we allocateevent_workright before we queue it. So don't bother at all.Signed-off-by Ilya Dryomov <[email protected]>--- net/ceph/osd_client.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)net/ceph/osd_client.c +5
-10@@ -2355,26 +2355,21 @@ static void handle_watch_notify(structceph_osd_client *osdc, if (event) { event_work =kmalloc (sizeof (*event_work),GFP_NOIO );if (!event_work) { -dout ("ERROR: could not allocate event_work\n" ); - goto done_err; +pr_err ("couldn't allocate event_work\n" ); +ceph_osdc_put_event (event); +return ; }INIT_WORK (&event_work->work, do_event_work); event_work->event = event; event_work->ver = ver; event_work->notify_id = notify_id; event_work->opcode = opcode; -if (!queue_work (osdc->notify_wq, &event_work->work)) { -dout ("WARNING: failed to queue notify event work\n" ); - goto done_err; - } + +queue_work (osdc->notify_wq, &event_work->work); }return ; -done_err: -ceph_osdc_put_event (event); -return ; - bad:pr_err ("osdc handle_watch_notify corrupt msg\n" );}
Quoted 25 lines · Alex Elder
Quoted 14 lines · Ilya Dryomov
Quoted 12 lines · Alex Elder
Quoted 7 lines · On 09/10/2014 07:20 PM, [email protected] wrote:
From: Li RongQing <[email protected]>
event_workshould be freed when adding it to queue failedSigned-off-by Li RongQing <[email protected]>Quoted 8 lines
Quoted 3 lines
Looks good.
Reviewed-by Alex Elder <[email protected]>Hmm,
queue_work()returns %false if @work was already on a queue, %true otherwise, so this seems bogus to me. I'd go with something like this (mangled).
Quoted 4 lines
The original change was fine. Whether it matters is another question. Your suggestion looks good as well, and on the assumption that if you choose to use it instead your "real" fix is done correctly you can use "Reviewed-by: <me>" if you like.
Well, the original change makes something bogus even more bogus. It's basically:
foo = kmalloc(...);
foo->bar = 0;
if (foo->bar & BAZ) {
/* WARNING */
kfree(foo);
goto ...
}So yeah, I'm going to use your Reviewed-by on my "real" fix ;)
Thanks,
Ilya