-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rgw: fix resource leak in rgw_bucket.cc and rgw_user.cc #17249
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I have updated the PR URL in Coverity. Please update it by yourself from the next time onwards.
Ok, I will update the PR URL in Coverity next time, and thank you for your help. @joscollin |
src/rgw/rgw_user.cc
Outdated
@@ -2781,6 +2781,7 @@ class RGWUserMetadataHandler : public RGWMetadataHandler { | |||
int ret = store->list_raw_objects_init(store->get_zone_params().user_uid_pool, marker, | |||
&info->ctx); | |||
if (ret < 0) { | |||
delete info; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, good catch! i'm fine with this fix as is it, but we might consider taking it step further with std::unique_ptr
:
auto info = ceph::make_unique<list_keys_info>();
...
*phandle = (void *)info.release();
the only advantage here being exception safety in the event that store->list_raw_objects_init()
throws
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbodley You mean we can handle it like this:
auto info = ceph::make_unique<list_keys_info>();
...
int ret = store->list_raw_objects_init(store->get_zone_params().domain_root, marker,
&info->ctx);
if (ret < 0) {
*phandle = (void *)info.release();
return ret;
}
*phandle = (void *)info;
So that we can handle store->list_raw_objects_init
throws safety.
Did I catch the point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbodley That's a good point. Make it std::unique_ptr
and let it delete itself when it goes out of scope / throws / returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*phandle = (void *)info.release();
@scienceluo I think this will again leak.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joscollin So what's the exact way to solve this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joscollin I found some delete
case like this in other functions, maybe we can open another PR to fix this like @cbodley and you said. @joscollin @cbodley what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scienceluo Yes, you can do that. But let's confirm this fix first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @scienceluo @joscollin. looks good, but the comments are a bit redundant
edit: build failure from missing #include "common/backport14.h"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbodley @joscollin Fixed, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but the comments are a bit redundant
@cbodley Yes, I have put the comments only to explain the change to @scienceluo.
Sorry for the late response, I was on leave.
2efefb1
to
2cee309
Compare
Signed-off-by: Luo Kexue <luo.kexue@zte.com.cn>
Close for #17353 instead. |
Fix coverity check:
CID 1416847 (#1 of 1): Resource leak (RESOURCE_LEAK)
4. leaked_storage: Variable info going out of scope leaks the storage it points to.
CID 1416844 (#1 of 1): Resource leak (RESOURCE_LEAK)
4. leaked_storage: Variable info going out of scope leaks the storage it points to.
CID 1416843 (#1 of 1): Resource leak (RESOURCE_LEAK)
4. leaked_storage: Variable info going out of scope leaks the storage it points to.
Signed-off-by: Luo Kexue luo.kexue@zte.com.cn