From: NeilBrown <neilb@suse.de>
To: Sudheendra Sampath <sudheendra.sampath@gmail.com>,
lustre-devel@lists.lustre.org
Subject: Re: [lustre-devel] Isn't there a memory leak here !!!
Date: Thu, 21 Jan 2021 14:51:39 +1100 [thread overview]
Message-ID: <87o8hjhrqs.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <CABnqofw_6U0gV8_A3gMOpX=wYMEFH5A6Pdy833EQoAWE271eXw@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 2159 bytes --]
On Wed, Jan 20 2021, Sudheendra Sampath wrote:
> Hi,
>
> While doing transaction code analysis, I found the following in
> lustre/target/tgt_lastrcvd.c.
>
> 552 int tgt_new_client_cb_add(struct thandle *th, struct obd_export
> *exp)
> 553 {
> 554 struct tgt_new_client_callback *ccb;
> 555 struct dt_txn_commit_cb *dcb;
> 556 int rc;
> 557
> * 558 OBD_ALLOC_PTR(ccb);*
> 559 if (ccb == NULL)
> 560 return -ENOMEM;
> 561
> 562 ccb->lncc_exp = class_export_cb_get(exp);
> 563
> 564 dcb = &ccb->lncc_cb;
> 565 dcb->dcb_func = tgt_cb_new_client;
> 566 INIT_LIST_HEAD(&dcb->dcb_linkage);
> 567 strlcpy(dcb->dcb_name, "tgt_cb_new_client",
> sizeof(dcb->dcb_name));
> 568
> 569 rc = dt_trans_cb_add(th, dcb);
> 570 if (rc) {
> 571 class_export_cb_put(exp);
> * 572 OBD_FREE_PTR(ccb);*
> 573 }
> 574 return rc;
> 575 }
>
> OBD_FREE_PTR() is in the condition block which means that the expectation
> is dt_trans_cb_add() returns something "!= 0".
>
> From the code, osd_trans_cb_add() and osp_trans_cb_add() returns zero
> value. So, my point is OBD_FREE_PTR() should be outside the condition
> block.
>
> Please correct me if my understanding is incorrect.
If dt_trans_cb_add() returns zero, then 'dcb' has been added to some
list of transactions. dcb is a pointer to a 'struct dt_txn_commit_cb'
structure embedded inside 'ccb'.
So when rc==0, the memory allocated for ccb is now attached to a list of
transactions, so it would be wrong to free it. If the attachment
(dt_trans_cb_add()) failed, then it needs to be freed.
So I think the code is correct as it stands.
Thanks,
NeilBrown
>
> --
> Regards
>
> Sudheendra Sampath
> _______________________________________________
> lustre-devel mailing list
> lustre-devel@lists.lustre.org
> http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 853 bytes --]
[-- Attachment #2: Type: text/plain, Size: 165 bytes --]
_______________________________________________
lustre-devel mailing list
lustre-devel@lists.lustre.org
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org
prev parent reply other threads:[~2021-01-21 3:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-20 21:55 [lustre-devel] Isn't there a memory leak here !!! Sudheendra Sampath
2021-01-21 3:51 ` NeilBrown [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o8hjhrqs.fsf@notabene.neil.brown.name \
--to=neilb@suse.de \
--cc=lustre-devel@lists.lustre.org \
--cc=sudheendra.sampath@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).