Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-65684

QModbusRtuSerialMaster lead to memory corruption at second instanciation.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Done
    • Affects Version/s: 5.9.2, 5.9.3, 5.10.0, 5.11.0
    • Fix Version/s: 5.11.3, 5.12.0 Beta 3
    • Component/s: SerialBus: MOD Bus
    • Labels:
      None
    • Environment:
      Ubuntu 17.04
       gcc 6.3.0
       Qt 5.9.2, Qt5.10.0, Qt5.11.0

      Ubuntu 14.04
       gcc 4.8.4
       Qt 5.9.3, Qt5.10.0

       
    • Commits:
      864e4a8ab514ddcd7f79106a6b447f7a1d5b5d4e (qt/qtserialbus/5.11)

      Description

      A timer is connected to a slot that initializes a QModbusRtuSerialMaster to send a request and wait for the reply.

      First time the slot is called I receive the good response, second time I get a memory corruption.

      I create a minimal project example that reproduce the error, code is attached but here is my slot:

      void MainWindow::onTimerTimeout()
      {
         qDebug("slot called");
      
         QModbusRtuSerialMaster _modbusSerialMaster;
         _modbusSerialMaster.setConnectionParameter(QModbusDevice::SerialDataBitsParameter, QSerialPort::Data8);
         _modbusSerialMaster.setConnectionParameter(QModbusDevice::SerialParityParameter, QSerialPort::NoParity);
         _modbusSerialMaster.setConnectionParameter(QModbusDevice::SerialStopBitsParameter, QSerialPort::OneStop);
         _modbusSerialMaster.setConnectionParameter(QModbusDevice::SerialBaudRateParameter, QSerialPort::Baud115200);
         _modbusSerialMaster.setConnectionParameter(QModbusDevice::SerialPortNameParameter, "/dev/ttyUSB0");
         _modbusSerialMaster.setNumberOfRetries(2);
      
         if(_modbusSerialMaster.connectDevice())
         {
            qDebug("connected");
            QModbusDataUnit request = QModbusDataUnit(QModbusDataUnit::HoldingRegisters, 511, 3);
      
            if(auto *reply = _modbusSerialMaster.sendReadRequest(request, 9))
            {
               qDebug("reply");
      
               while(!reply->isFinished())
               {
                  QCoreApplication::processEvents(QEventLoop::AllEvents);
               }
               qDebug() << reply->result().values();
      
               reply->deleteLater();
            }
            _modbusSerialMaster.disconnectDevice();
         }
      
         timer.start();
      }
      

      and the output:

       

       

      slot called
      connected
      reply
      QVector(17920, 30676, 0)
      slot called
      *** Error in `/home/malacasse/dev/build-testModbus-Desktop_Qt_5_9_2_GCC_64bit-Debug/testModbus': malloc(): memory corruption (fast): 0x0000555555b1a7ff ***
      ======= Backtrace: =========
      /lib/x86_64-linux-gnu/libc.so.6(+0x7908b)[0x7ffff633b08b]
      /lib/x86_64-linux-gnu/libc.so.6(+0x85008)[0x7ffff6347008]
      /lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x54)[0x7ffff6348984]
      /usr/lib/x86_64-linux-gnu/libstdc++.so.6(_Znwm+0x18)[0x7ffff692faf8]
      /opt/Qt/5.9.2/gcc_64/lib/libQt5SerialBus.so.5(_ZN22QModbusRtuSerialMasterC1EP7QObject+0x34d)[0x7ffff7385fbd]
      /home/malacasse/dev/build-testModbus-Desktop_Qt_5_9_2_GCC_64bit-Debug/testModbus(+0x3227)[0x555555557227]
      /home/malacasse/dev/build-testModbus-Desktop_Qt_5_9_2_GCC_64bit-Debug/testModbus(+0x44b3)[0x5555555584b3]
      /opt/Qt/5.9.2/gcc_64/lib/libQt5Core.so.5(_ZN11QMetaObject8activateEP7QObjectiiPPv+0x659)[0x7ffff6ecb869]
      /opt/Qt/5.9.2/gcc_64/lib/libQt5Core.so.5(_ZN6QTimer7timeoutENS_14QPrivateSignalE+0x27)[0x7ffff6ed8057]
      .......
       
      

        Attachments

        1. main.cpp
          0.2 kB
        2. mainwindow.cpp
          2 kB
        3. mainwindow.h
          0.3 kB
        4. testModbus.pro
          0.3 kB
        For Gerrit Dashboard: QTBUG-65684
        # Subject Branch Project Status CR V

          Activity

            People

            Assignee:
            ablasche Alex Blasche
            Reporter:
            malacasse Marc-Antoine Lacasse
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes