Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]SIGSEGV QArrayData::deallocate(QArrayData*, unsigned int, unsigned int)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]SIGSEGV QArrayData::deallocate(QArrayData*, unsigned int, unsigned int)

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 6.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    topix93
    wrote on last edited by
    #1

    @QByteArray buffer; //declared as public in the header file

    void MyClass::run(){

    while(!bQuit){
        mutex.lock();
        buffer = readData(); // On this line i get the SIGSEGV
        mutex.unlock();
    }
    

    }@

    the method readData() return a QByteArray

    the backtrace is:
    @>&"bt\n"

    ~"#0 0xb7fdd424 in __kernel_vsyscall ()\n"
    ~"#1 0xb6c011df in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64\n"
    ~"#2 0xb6c04825 in __GI_abort () at abort.c:91\n"
    ~"#3 0xb6c3e39a in __libc_message (do_abort=2, fmt=0xb6d39888 "*** glibc detected *** %s: %s: 0x%s **\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:201\n"
    ~"#4 0xb6c48ee2 in malloc_printerr (action=<optimized out>, str=<optimized out>, ptr=0xaeb5a2a8) at malloc.c:5039\n"
    ~"#5 0xb6f25eb5 in QArrayData::deallocate(QArrayData
    , unsigned int, unsigned int) () from /home/tizio/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
    ~"#6 0xb6f27cd0 in QByteArray::operator=(QByteArray const&) () from /home/tizio/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
    ~"#7 0x0806a68f in MyClass::run (this=0x81a20c0) at ../Project/myclass.cpp:60\n"
    ~"#8 0xb6f253a9 in ?? () from /home/tizio/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5\n"
    ~"#9 0xb6856d4c in start_thread (arg=0xafcfdb40) at pthread_create.c:308\n"
    ~"#10 0xb6cc2bae in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130\n"
    197^done@

    This error don't appears always, only sometimes

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      What does MyClass inherit?

      How did you implement readData()?

      How are you using your threads?

      I recommend reading "this page":http://doc-snapshot.qt-project.org/qt5-stable/threads-synchronizing.html for info about transferring data between threads. Also see "this page":http://doc-snapshot.qt-project.org/qt5-stable/threads-technologies.html for recommendations how to use threads.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • T Offline
        T Offline
        topix93
        wrote on last edited by
        #3

        1 - MyClass inherits QThread.

        2 - i have a class Utility with the public method readData(), for this class i use the extern keyword : "extern Utility mUtility;"
        in the read data method i write the following code:

        @int iPlcConnResult = 0;

        QByteArray buff;
        buff.clear();

        unsigned char data = (unsigned char)malloc(length);

        //mutexPlcSocket.lock();
        iPlcConnResult = readBytes(conn, tipoArea, numDB, startAddress, length, data);
        //mutexPlcSocket.unlock();

        bPlcConnError = (iPlcConnResult != 0);
        if (!bPlcConnError)
        buff = buff.setRawData((char*) data, length);
        else
        sPlcConnError = "Error " + QString::number(iPlcConnResult) + " - " + daveStrerror(iPlcConnResult);

        return buff;@

        3 - i start the thread with myThread.start(QThread::HighestPriority);

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi,

          There isn't enough code to know for sure what's the cause, but you really shouldn't be using malloc in C++. There are safer ways to allocate memory.

          Using C-style casts can be dangerous too. Use static_cast<> instead. http://stackoverflow.com/questions/103512/in-c-why-use-static-castintx-instead-of-intx

          Questions:

          • Where did you call free?
          • Is Utility thread-safe?

          Try this, instead of calling malloc and QByteArray::setRawData():
          @
          // Create an heap-allocated array, filled with null bytes
          QByteArray buff(length, '\0');

          iPlcConnResult = readBytes(conn, tipoArea, numDB, startAddress,
          length, static_cast<unsigned char*>(buff.data()));
          @

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • C Offline
            C Offline
            carallen9988
            wrote on last edited by
            #5

            I have been through with this same problem too. Thanks for the help!

            To find out more about <a href="http://www.lenovo.com/government/us/en/federal/index.html">computers for government</a>, check out this site.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved