Hi Han-Lin-

This is a bug we've seen before.  It is caused because the Android
compilation options are different enough from the shared-object
compilation options, resulting in some incompatible allocations in
std::string inside of this object.

We have 2 possible solutions.  

First, you can move all constructor/destructors for this object inside
of the .cpp file, like in this review:
https://gerrit.iotivity.org/gerrit/#/c/364/

This way is a bit icky, so we decided to use the second choice:
The second option, which we chose, was to change gnustl's linking model
to static, to prevent this difference:
https://gerrit.iotivity.org/gerrit/#/c/425

Both are pretty easy changes that can fix your issue.  Alternatively,
the 2nd option is currently in our master, so if you can get to the git
server, a simple pull from master should give you the fix for this.

Thanks!
-Erich Keane


On Wed, 2015-03-18 at 10:51 +0800, Han-Lin Li wrote:
> I used valgrind to trace segmentation fault point.
> It crashed in destructor of OCRepresentation.
> Anyone have any idea?
> 
> 
> ==6406== Thread 3:
> ==6406== Invalid free() / delete / delete[] / realloc()
> ==6406==    at 0x481A50C: free (vg_replace_malloc.c:473)
> ==6406==    by 0x1B472B: _M_dispose (basic_string.h:249)
> ==6406==    by 0x1B472B: std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::~basic_string()
> (basic_string.h:547)
> ==6406==    by 0x16302B: OC::OCRepresentation::~OCRepresentation() (in
> /data/simpleclient)
> ==6406==    by 0x16548B:
> putLightRepresentation(std::shared_ptr<OC::OCResource>)
> (simpleclient.cpp:264)
> ==6406==    by 0x1658BB:
> onGet(std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> > const&,
> OC::OCRepresentation const&, int) (simpleclient.cpp:287)
> ==6406==    by 0x168FA3: std::_Function_handler<void
> (std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> > const&,
> OC::OCRepresentation const&, int), void
> (*)(std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> > const&,
> OC::OCRepresentation const&, int)>::_M_invoke(std::_Any_data const&,
> std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> > const&,
> OC::OCRepresentation const&, int) (functional:2039)
> ==6406==    by 0x4BA23BB: std::function<void
> (std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> > const&,
> OC::OCRepresentation const&,
> int)>::operator()(std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> > const&,
> OC::OCRepresentation const&, int) const (functional:2439)
> ==6406==    by 0x4BA1B7F: void std::_Bind_simple<std::function<void
> (std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> > const&,
> OC::OCRepresentation const&, int)>
> (std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> >,
> OC::OCRepresentation, OCStackResult)>::_M_invoke<0u, 1u,
> 2u>(std::_Index_tuple<0u, 1u, 2u>) (functional:1700)
> ==6406==    by 0x4BA0F77: std::_Bind_simple<std::function<void
> (std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> > const&,
> OC::OCRepresentation const&, int)>
> (std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> >,
> OC::OCRepresentation, OCStackResult)>::operator()() (functional:1688)
> ==6406==    by 0x4BA0AFF:
> std::thread::_Impl<std::_Bind_simple<std::function<void
> (std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> > const&,
> OC::OCRepresentation const&, int)>
> (std::vector<OC::HeaderOption::OCHeaderOption,
> std::allocator<OC::HeaderOption::OCHeaderOption> >,
> OC::OCRepresentation, OCStackResult)> >::_M_run() (thread:115)
> ==6406==    by 0x4BCC6CB: execute_native_thread_routine (thread.cc:84)
> ==6406==    by 0x483F5BF: __pthread_start(void*) (in /system/lib/libc.so)
> ==6406==  Address 0x4c0f19c is 0 bytes inside data symbol
> "_ZNSs4_Rep20_S_empty_rep_storageE"
> 
> 2015-02-27 4:03 GMT+08:00 Lenahan, Charlie <charlie.lenahan at intel.com>:
> > You should be able to run
> >         adb shell dumpsys dropbox SYSTEM_TOMBSTONE ?print  > foo.crash
> >
> > that will give you the crash dump. You can then get a stack trace
> >         ndk-stack -dump foo.crash -sym
> > /path/to/your/simpleclient/obj/local/target_abi/
> >
> >
> >
> >
> > Charlie Lenahan
> >    | Software Engineer  | Intel Corporation | 322 West Main Street  |
> > Louisville, KY 40202  | W - 502.963.0917  | 8-963.0917
> > charlie.lenahan at intel.com  | CDG ? WINS ? WSS EAST   |
> > http://www.linkedin.com/in/charlielenahan
> >
> >
> >
> > On 2/26/15, 6:10 AM, "Han-Lin Li" <astereae at gmail.com> wrote:
> >
> >>I run simpleclient and simpleserver by adb and get a segmentation fault
> >>
> >>
> >>
> >>Here is the debug message
> >>
> >>
> >>
> >>Getting Light Representation...
> >>
> >>v:1 t:1 tkl:8 c:1 id:65355 o: [ 7:'\xB5\x95', 11:'a', 11:'light' ]
> >>
> >>Jan 16 00:49:27 DEBG bytes_written 23
> >>
> >>Jan 16 00:49:27 DEBG coap_read: discarded invalid frame
> >>
> >>Jan 16 00:49:27 DEBG coap_read: discarded invalid frame
> >>
> >>Jan 16 00:49:27 DEBG coap_read: discarded invalid frame
> >>
> >>Jan 16 00:49:27 DEBG coap_read: discarded invalid frame
> >>
> >>Jan 16 00:49:27 DEBG set data to 0xf6d5b0a6 (pdu ends at 0xf6d5b0f9)
> >>
> >>Jan 16 00:49:27 DEBG ** received 105 bytes from :
> >>
> >>v:1 t:1 tkl:8 c:64 id:65355 o: [ 11:'\x01', 12:'\x32',
> >>14:'\xFF\xFF\x02\x00' ]
> >>
> >>:{"oc":[{"href":"/a/light","rep":{"name":"John's
> >>light","power":0,"state":false
> >>
> >>}]}\x00
> >>
> >>Jan 16 00:49:27 DEBG coap_read: discarded invalid frame
> >>
> >>GET request was successful
> >>
> >>Resource URI: /a/light
> >>
> >>        state: false
> >>
> >>        power: 0
> >>
> >>        name: John's light
> >>
> >>Putting light representation...
> >>
> >>v:1 t:1 tkl:8 c:3 id:65356 o: [ 7:'\xB5\x95', 11:'a', 11:'light' ]
> >>d:{"oc":[{"r
> >>
> >>p":{"power":15,"state":true}}]}\x00
> >>
> >>Jan 16 00:49:27 DEBG bytes_written 67
> >>
> >>Segmentation fault (core dumped)
> >>
> >>
> >>
> >>It should crash in resource->put(rep, QueryParamsMap(), &onPut);
> >>Any body knows why?
> >>_______________________________________________
> >>iotivity-dev mailing list
> >>iotivity-dev at lists.iotivity.org
> >>https://lists.iotivity.org/mailman/listinfo/iotivity-dev
> _______________________________________________
> iotivity-dev mailing list
> iotivity-dev at lists.iotivity.org
> https://lists.iotivity.org/mailman/listinfo/iotivity-dev

Reply via email to