All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gowtham Anandha Babu <gowtham.ab@samsung.com>
To: 'Luiz Augusto von Dentz' <luiz.dentz@gmail.com>
Cc: linux-bluetooth@vger.kernel.org,
	'Bharat Panda' <bharat.panda@samsung.com>,
	cpgs@samsung.com
Subject: RE: [PATCH v1 1/3] shared/gatt-helpers: Fix usage of freed memory
Date: Wed, 28 Jan 2015 19:48:02 +0530	[thread overview]
Message-ID: <001f01d03b05$51536700$f3fa3500$@samsung.com> (raw)
In-Reply-To: <CABBYNZK2WoRzxzkgQRsgUe0pjYzY0M1Ee0Ncx+n+J+iQmEpCkg@mail.gmail.com>

Hi Luiz,

> -----Original Message-----
> From: Luiz Augusto von Dentz [mailto:luiz.dentz@gmail.com]
> Sent: Wednesday, January 28, 2015 6:37 PM
> To: Gowtham Anandha Babu
> Cc: linux-bluetooth@vger.kernel.org; Bharat Panda; cpgs@samsung.com
> Subject: Re: [PATCH v1 1/3] shared/gatt-helpers: Fix usage of freed memory
> 
> Hi Gowtham,
> 
> On Tue, Jan 27, 2015 at 10:53 AM, Gowtham Anandha Babu
> <gowtham.ab@samsung.com> wrote:
> > src/shared/gatt-helpers.c:709:6: warning: Use of memory after it is freed
> >         if (op->callback)
> >             ^~~~~~~~~~~~
> > src/shared/gatt-helpers.c:780:6: warning: Use of memory after it is freed
> >         if (op->callback)
> >             ^~~~~~~~~~~~
> > src/shared/gatt-helpers.c:998:6: warning: Use of memory after it is freed
> >         if (op->callback)
> >             ^~~~~~~~~~~~
> > src/shared/gatt-helpers.c:1020:32: warning: Use of memory after it is freed
> >                 op->callback(false, 0, NULL, data->op->user_data);
> >                                              ^~~~~~~~
> > src/shared/gatt-helpers.c:1112:6: warning: Use of memory after it is freed
> >         if (op->callback)
> >             ^~~~~~~~~~~~
> > src/shared/gatt-helpers.c:1226:6: warning: Use of memory after it is freed
> >         if (op->callback)
> >             ^~~~~~~~~~~~
> > src/shared/gatt-helpers.c:1332:6: warning: Use of memory after it is freed
> >         if (op->callback)
> >             ^~~~~~~~~~~~
> > src/shared/gatt-helpers.c:1452:6: warning: Use of memory after it is freed
> >         if (op->callback)
> >             ^~~~~~~~~~~~
> > ---
> >  src/shared/gatt-helpers.c | 25 ++++++++++++++++---------
> >  1 file changed, 16 insertions(+), 9 deletions(-)
> >
> > diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
> > index 3864ed0..c9b24cc 100644
> > --- a/src/shared/gatt-helpers.c
> > +++ b/src/shared/gatt-helpers.c
> > @@ -686,7 +686,6 @@ static void read_by_grp_type_cb(uint8_t opcode,
> const void *pdu,
> >                                                         discovery_op_unref))
> >                         return;
> >
> > -               discovery_op_unref(op);
> >                 success = false;
> >                 goto done;
> >         }
> > @@ -708,6 +707,8 @@ success:
> >  done:
> >         if (op->callback)
> >                 op->callback(success, att_ecode, final_result,
> > op->user_data);
> > +
> > +       discovery_op_unref(op);
> >  }
> >
> >  static void find_by_type_val_cb(uint8_t opcode, const void *pdu, @@
> > -766,7 +767,6 @@ static void find_by_type_val_cb(uint8_t opcode, const
> void *pdu,
> >                                                         discovery_op_unref))
> >                         return;
> >
> > -               discovery_op_unref(op);
> >                 success = false;
> >                 goto done;
> >         }
> > @@ -779,6 +779,8 @@ success:
> >  done:
> >         if (op->callback)
> >                 op->callback(success, att_ecode, final_result,
> > op->user_data);
> > +
> > +       discovery_op_unref(op);
> >  }
> >
> >  static bool discover_services(struct bt_att *att, bt_uuid_t *uuid, @@
> > -977,7 +979,6 @@ static void read_included_cb(uint8_t opcode, const void
> *pdu,
> >                                 discovery_op_ref(op), discovery_op_unref))
> >                         return;
> >
> > -               discovery_op_unref(op);
> >                 success = false;
> >                 goto done;
> >         }
> > @@ -997,6 +998,8 @@ static void read_included_cb(uint8_t opcode, const
> > void *pdu,
> >  done:
> >         if (op->callback)
> >                 op->callback(success, att_ecode, final_result,
> > op->user_data);
> > +
> > +       discovery_op_unref(op);
> >  }
> >
> >  static void read_included(struct read_incl_data *data) @@ -1014,10
> > +1017,10 @@ static void read_included(struct read_incl_data *data)
> >                                                         read_included_unref))
> >                 return;
> >
> > -       read_included_unref(data);
> > -
> >         if (op->callback)
> >                 op->callback(false, 0, NULL, data->op->user_data);
> > +
> > +       read_included_unref(data);
> >  }
> >
> >  static void discover_included_cb(uint8_t opcode, const void *pdu, @@
> > -1099,7 +1102,6 @@ static void discover_included_cb(uint8_t opcode,
> const void *pdu,
> >                                                         discovery_op_unref))
> >                         return;
> >
> > -               discovery_op_unref(op);
> >                 success = false;
> >                 goto failed;
> >         }
> > @@ -1111,6 +1113,8 @@ done:
> >  failed:
> >         if (op->callback)
> >                 op->callback(success, att_ecode, final_result,
> > op->user_data);
> > +
> > +       discovery_op_unref(op);
> >  }
> >
> >  bool bt_gatt_discover_included_services(struct bt_att *att, @@
> > -1213,7 +1217,6 @@ static void discover_chrcs_cb(uint8_t opcode, const
> void *pdu,
> >                                                 discovery_op_unref))
> >                         return;
> >
> > -               discovery_op_unref(op);
> >                 success = false;
> >                 goto done;
> >         }
> > @@ -1226,6 +1229,8 @@ done:
> >         if (op->callback)
> >                 op->callback(success, att_ecode, final_result,
> >
> > op->user_data);
> > +
> > +       discovery_op_unref(op);
> >  }
> >
> >  bool bt_gatt_discover_characteristics(struct bt_att *att, @@ -1321,7
> > +1326,6 @@ static void read_by_type_cb(uint8_t opcode, const void *pdu,
> >                                                 discovery_op_unref))
> >                         return;
> >
> > -               discovery_op_unref(op);
> >                 success = false;
> >                 goto done;
> >         }
> > @@ -1332,6 +1336,8 @@ done:
> >         if (op->callback)
> >                 op->callback(success, att_ecode, success ? op->result_head :
> >                                                         NULL,
> > op->user_data);
> > +
> > +       discovery_op_unref(op);
> >  }
> >
> >  bool bt_gatt_read_by_type(struct bt_att *att, uint16_t start,
> > uint16_t end, @@ -1439,7 +1445,6 @@ static void
> discover_descs_cb(uint8_t opcode, const void *pdu,
> >                                                 discovery_op_unref))
> >                         return;
> >
> > -               discovery_op_unref(op);
> >                 success = false;
> >                 goto done;
> >         }
> > @@ -1451,6 +1456,8 @@ success:
> >  done:
> >         if (op->callback)
> >                 op->callback(success, att_ecode, final_result,
> > op->user_data);
> > +
> > +       discovery_op_unref(op);
> >  }
> >
> >  bool bt_gatt_discover_descriptors(struct bt_att *att,
> > --
> > 1.9.1
> 
> These were actually false positives of your static analyzer, in all occurrences
> there are actually extra references preventing the memory to be freed
> before use, next time please take the time to test this or even better create
> a unit test to reproduce the problem. For this specifically I had done
> something to track the actual pending operation but for gatt-client changes I
> would have had to change some APIs to do it properly and because of that I
> just revert it, perhaps it is worth doing something similar there if it continues
> to show as a problem in the static analyzers.
> 

Sorry for the false positives. I will check once again and test it before sending.
Meanwhile I am using clang static analyzer for testing. I did git pull and ran the tool.
It gave me the following warnings:

src/shared/gatt-helpers.c:851:9: warning: Use of memory after it is freed
        return op->id ? true : false;
               ^~~~~~
1 warning generated.

src/shared/gatt-client.c:534:14: warning: Use of memory after it is freed
        op->success = false;
        ~~~~~~~~~~~ ^
src/shared/gatt-client.c:689:14: warning: Use of memory after it is freed
        op->success = success;
        ~~~~~~~~~~~ ^
src/shared/gatt-client.c:790:14: warning: Use of memory after it is freed
        op->success = success;
        ~~~~~~~~~~~ ^
src/shared/gatt-client.c:882:14: warning: Use of memory after it is freed
        op->success = success;
        ~~~~~~~~~~~ ^
src/shared/gatt-client.c:950:14: warning: Use of memory after it is freed
        op->success = success;
        ~~~~~~~~~~~ ^
src/shared/gatt-client.c:2328:2: warning: Use of memory after it is freed
        complete_write_long_op(req, success, 0, false);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2350:2: warning: Use of memory after it is freed
        request_unref(req);
        ^~~~~~~~~~~~~~~~~~
7 warnings generated.

I think the gatt-helpers:  warning seems valid for me. But in gatt-client it is still
giving the warnings. Is it still false positive?

Regards,
Gowtham Anandha Babu

> 
> --
> Luiz Augusto von Dentz


  reply	other threads:[~2015-01-28 14:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-27  8:53 [PATCH v1 0/3] Fix memory issues and trivial code cleaup Gowtham Anandha Babu
2015-01-27  8:53 ` [PATCH v1 1/3] shared/gatt-helpers: Fix usage of freed memory Gowtham Anandha Babu
2015-01-28 13:07   ` Luiz Augusto von Dentz
2015-01-28 14:18     ` Gowtham Anandha Babu [this message]
2015-01-28 14:20       ` Luiz Augusto von Dentz
2015-01-27  8:53 ` [PATCH v1 2/3] shared/gatt-client: " Gowtham Anandha Babu
2015-01-27  8:53 ` [PATCH v1 3/3] tools/hciattach_ath3k: Remove dead code warnings Gowtham Anandha Babu
2015-01-27 13:39 ` [PATCH v1 0/3] Fix memory issues and trivial code cleaup Luiz Augusto von Dentz

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='001f01d03b05$51536700$f3fa3500$@samsung.com' \
    --to=gowtham.ab@samsung.com \
    --cc=bharat.panda@samsung.com \
    --cc=cpgs@samsung.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.