OSDN Git Service

Fix GKI buffer leak with discovery information service reading
authorMike J. Chen <mjchen@google.com>
Sat, 28 Jun 2014 02:01:10 +0000 (19:01 -0700)
committerMike J. Chen <mjchen@google.com>
Fri, 11 Jul 2014 18:41:02 +0000 (11:41 -0700)
commiteaf796f1dc6a0e719c8f957f629b35c4faf2c01a
tree745a6543e114a308707ef0d1c0733c3546593551
parent335aa36bca8532874c23c1afe5bfc2aff7fc01a5
Fix GKI buffer leak with discovery information service reading

If the discovery information service of the LE client has
the fields model number, serial number, fw version, etc,
the service would allocate PKI buffer and never do anything
with it, so it would leak.  It looks like it should have
been assigned the a callback string array, however fixing
that still doesn't fix the leak because the code that receives
the string array, bta_hh_le_dis_cback(), never uses it and
never frees it.

I believe the semantic is that the string arrays are kept around
as a cache in the srvc engine connection structure,
so it's the srvc engine dealloc of the callback structure that
needs to also free the string buffers if they have been allocated.
After fixing the string array allocation, add code to free the
string array entries if they are not null.

Also fixed an off by one error in DIS_SrUpdate() that would also lead
to a GKI buffer leak.

Improve two string termination cases to use a simple set of the
last entry in the char array instead of memsetting the whole array
when most of it will be filled by a following memcpy.

Change-Id: I7905cd771dbbe166e3c2b42e019bac9f5a312877
Signed-off-by: Mike J. Chen <mjchen@google.com>
stack/srvc/srvc_dis.c
stack/srvc/srvc_eng.c