Results 1 to 20 of 22

Thread: Memory corruption related to signal emission?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Memory corruption related to signal emission?

    I suspect I'm dealing with memory corruption somewhere in my program. I'm getting a SIGSEGV on a call to a function from a trusted third-party library. With some trial and error I've discovered that this segfault happens when the lines

    Qt Code:
    1. emit newStreamFound(_streams[streamOneSSRC]);
    2. emit newStreamFound(_streams[streamTwoSSRC]);
    To copy to clipboard, switch view to plain text mode 

    are not commented. This happens even when no slots are connected to this signal. As far as I know there are no thread safety issues. I ran a Valgrind memory analysis with these lines disabled and this is what came up:



    I can't make heads or tails of this output. The test condition in the do while loop depends on one variable that is, in fact, initialized at the top of the function. Does any of this point to issues that should be investigated? If not, what are the next steps I can take?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory corruption related to signal emission?

    right, so have you debugged the values of streamOneSSRC, and the array value at that index?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory corruption related to signal emission?

    I should probably mention that _streams is a QMap. streamOneSSRC and streamTwoSSRC are uint32_t with values similar to 738621152 and 3435571404. I've asserted that

    Qt Code:
    1. assert(_streams.find(streamOneSSRC) != _streams.end());
    2. assert(_streams.find(streamTwoSSRC) != _streams.end());
    To copy to clipboard, switch view to plain text mode 

    right before the signal emission happens.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Memory corruption related to signal emission?

    Why do you think this is related to signal emission, and not to accessing the QMap ?
    Does it crash if you just print the values ?
    Qt Code:
    1. // emit newStreamFound(_streams[streamOneSSRC]);
    2. // emit newStreamFound(_streams[streamTwoSSRC]);
    3. qDebug() << _streams[streamOneSSRC];
    4. qDebug() << _streams[streamTwoSSRC];
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory corruption related to signal emission?

    Nope, that seems to work just fine.

    Qt Code:
    1. VideoStream(0x7fffe4110e20)
    2. VideoStream(0x7fffe4110e90)
    To copy to clipboard, switch view to plain text mode 

    But then again if I'm dealing with a memory corruption bug this behavior could be undefined.

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory corruption related to signal emission?

    how are you pasing the data through the signaal/slot? const ref?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory corruption related to signal emission?

    By pointer.

    Qt Code:
    1. void newStreamFound(VideoStream*);
    To copy to clipboard, switch view to plain text mode 

    _streams is a QMap<uint32_t, VideoStream*>.

  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory corruption related to signal emission?

    you've got a problem somewhere else then. emitting a signal with a pointer as an argument, and with no slots connected, does not cause a seg fault.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  9. #9
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory corruption related to signal emission?

    Right... so it's likely to be memory corruption like I thought then? Can you conclude anything from the Valgrind memory analysis about where the error might be?

  10. #10
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Memory corruption related to signal emission?

    seg fault is always doing something dodgy to memory isnt it?

    valgrind doesnt play too nicely with qt from what little I have read about it so not sure you can conclude much from it.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  11. #11
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Memory corruption related to signal emission?

    Build debug version, launch with debugger and examine (post here) backtrace after crash.

Similar Threads

  1. Replies: 2
    Last Post: 7th December 2010, 15:13
  2. memory corruption
    By Rambobino in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2010, 21:35
  3. Replies: 3
    Last Post: 19th January 2010, 20:26
  4. Workload to the Application:Related to Signal and Slot
    By soumyadeep_pan in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2009, 11:08
  5. Replies: 3
    Last Post: 11th January 2008, 17:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.