Android Bug (ii)-Wild pointer in surfacetexture

Source: Internet
Author: User

The first time I encountered this bug, it was an irregular low probability, and finally found a more easily reproducible step:

Start the system
Then go to Google +
Create a new account (note that you are creating a new account)
It's been restarted in a few steps.

This bug, the beginning of tracking is also no clue, in this bug appears, the system Debuggerd still have some problems, pt_regs set and the kernel does not correspond, tombstone information is completely useless, core dump function is also unable to use, The only clue is a little bit of logcat Trace, trace as follows:

D/openglrenderer (2021): Flushing caches (Mode 1) d/openglrenderer (2021): Flushing caches (Mode 0) d/openglrenderer (1986) : Flushing caches (Mode 1) w/surfacetexture (1451): Freeallbufferslocked called but Mqueue was not emptyd/openglrenderer (19  : Flushing caches (Mode 0) f/libc (1451): Fatal signal One (SIGSEGV) at 0x00000024 (code=1) i/debug (1449): * * * * * * * * * * * * * * * * * * * * * * * * * * * ***I/DEBUG (1449): Build fingerprint: ' xxxx/iml74k/eng.freshui.201 20213.154128:user/test-keys ' I/debug (1449): pid:1451, tid:1455 >>>/system/bin/surfaceflinger <<<I /debug (1449): Signal (SIGSEGV), Code 1 (segv_maperr), fault addr 00000024

The current error is basically similar to the trace. Start looking for it from here. A word in the trace:

W/surfacetexture (1451): Freeallbufferslocked called but Mqueue was not empty

Is the biggest suspect, based on the experience of catching insects, first make assumptions, can already explain the cause and phenomenon of the error:

    • Mqueue is usually used by two modules, a enqueue, a dequeue
    • Error, to the mqueue to free, but mqueue not empty, indicating that someone is using
    • If this warning is not given, forcing the mqueue to free will most likely cause another module to use the free memory to cause a segment error

Turn back to see Code, SURFACETEXTURE.CPP, check the use of Mqueue, where there is a free buffer, Mqueue is not empty possible? Check it out, and really find it, look at this function:

[Java]View Plaincopy
  1. status_t surfacetexture::setbuffercount (int bufferCount) {
  2. ST_LOGV ("setbuffercount:count=%d", BufferCount);
  3. Mutex::autolock Lock (Mmutex);
  4. if (mabandoned) {
  5. St_loge ("Setbuffercount:surfacetexture has been abandoned!");
  6. return no_init;
  7. }
  8. if (BufferCount > Num_buffer_slots) {
  9. St_loge ("Setbuffercount:buffercount larger than slots available");
  10. return bad_value;
  11. }
  12. //Error out if the user has dequeued buffers
  13. For (int i=0; i<mbuffercount; i++) {
  14. if (mslots[i].mbufferstate = = Bufferslot::D equeued) {
  15. St_loge ("Setbuffercount:client owns some buffers");
  16. Return-einval;
  17. }
  18. }
  19. const int minbufferslots = Msynchronousmode?
  20. Min_sync_buffer_slots:min_async_buffer_slots;
  21. if (bufferCount = = 0) {
  22. Mclientbuffercount = 0;
  23. BufferCount = (Mserverbuffercount >= minbufferslots)?
  24. Mserverbuffercount:minbufferslots;
  25. return setbuffercountserverlocked (BufferCount);
  26. }
  27. if (BufferCount < minbufferslots) {
  28. St_loge ("setbuffercount:requested buffer count (%d) is less than"
  29. "Minimum (%d)", BufferCount, Minbufferslots);
  30. return bad_value;
  31. }
  32. //Here we ' re guaranteed that the client doesn ' t has dequeued buffers
  33. //And would release all of the its buffer references.
  34. Freeallbufferslocked ();
  35. Mbuffercount = BufferCount;
  36. Mclientbuffercount = BufferCount;
  37. Mcurrenttexture = Invalid_buffer_slot;
  38. Mqueue.clear ();
  39. Mdequeuecondition.signal ();
  40. return OK;
  41. }


After the problem is found, before the freeallbufferslocked () call, the mqueue will be drained, and so on, and so on the use of the client is finished and then free.

After the modification, no such errors have been encountered.

Of course, the problem of the troubleshooting and resolution process is not so smooth, but also for several days. The solution and the cause of the problem is not to elaborate, meet and prepare to catch the worm's classmates should see clearly.

Hehe, this again can be attributed to the problem of multi-threaded synchronization/state machine, basically I have a serious problem with Android is this kind of

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Bug (ii)-Wild pointer in surfacetexture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.