Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

VLD output error



  • Hello all,

    I use Qt to load two images and then call a image processing function. When I use Visual Leak Detector to check my code, the output of the tool is really strange. It indicates the largest number of used storage is GB, and it seems that I didn't call the function findItems() and processedPendingEvents().

    Below is the output of VLD and part of my code.
    Thx!

    part of the output of VLD tool: (It seems that function findItems() and processedPendingEvents() use large amount of storage?)

    WARNTING: Visual Leak Detector detected memory leaks !
    ---- Block 57 at 0x0000000005388730: 16 bytes ----
    Leak Hash: 0xD44F8893, Count: 1, Total 16 bytes
    Call Stack (TID 6752) :
    ucrtbased. dll!malloc ()
    f:\dd\vctools\crt\vcstartup\src\heap\new_scalar. cpp (19): camera. exe!operator new() + 0xA bytes
    d:\shx\test\camera\mainwindow. cpp(421): camera. exe!MainWindow: :ShowNV21() + 0xA bytes
    d:\shx\test\camera\mainwindow. cpp (407): camera. exe !MainWindow: : ShowNV21()
    d:\shx\test\camera\mainwindow. cpp (59): camera. exe!MainWindow: getfile10()
    d:\shx\test\camera\debug\moc_mainwindow. cpp (82): camera. exe!MainWindow::qt_static_metacall() + 0xA bytes 
    Qt5Cored. dll!QStateMachinePrivate::processedPendingEvents() + 0x524D4D bytes
    Qt5Cored. dll!QStatellachinePrivate::processedPendingEvents() + 0x512521 bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems() + 0x22DE48 bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems()  + 0x23009A bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems()  + 0x22F06A bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems() + 0x22E637 bytes
    Qt5Widgetsd. dll!QTreeWidget::findItems() + OxB1015 bytes
    
    Largest number used: 60004904 bytes.
    Total allocations: 90489954 bytes.
    

    part of my code: (I know that I didn't delete scene in ShowNV21(), but after I correct it, the largest number used shown in VLD is still very large)

    void MainWindow::getfile10()  
    {
    
        QString OpenFile;
        int Width = 0, Height = 0;
    
        OpenFile = QFileDialog::getOpenFileName(this,
            "please choose an image file",
            "",
            "Image Files(*.nv21 *.bmp);;All(*.*)");
        if (OpenFile != "")
        {
            char *File_Path = (char *)malloc(OpenFile.toStdString().length());
            strcpy(File_Path, OpenFile.toStdString().c_str());
            ShowNV21(File_Path, ui->graphicsView_27);
    
            GetNV21Size(OpenFile.toStdString().c_str(), &Width, &Height);
            ui->lineEdit_52->setText(QString::number(Width));
            ui->lineEdit_53->setText(QString::number(Height));
    
            imgNum = 2;
            Img_Info[0].Width = Width;
            Img_Info[0].Height = Height;
            Img_Info[0].File_Path = File_Path;
    
        }
    
    }
    
    oid MainWindow::ShowNV21(const char *File_Path, QGraphicsView *graphicsView)
    {
        int Width, Height;
        GetNV21Size(File_Path, &Width, &Height);
        MainWindow::ShowNV21(File_Path, graphicsView, Width, Height);
    }
    
    void MainWindow::ShowNV21(const char *File_Path, QGraphicsView *graphicsView, unsigned int Width, unsigned int Height)
    {
        unsigned char *NV21_Img= (unsigned char *)malloc(Width * Width * 3 / 2);
        unsigned char *RBG_Img = (unsigned char *)malloc(Width * Height * 3);
    
        FILE *Img = fopen(File_Path, "rb");
        fread(NV21_Img, Width * Width * 3 / 2, 1, Img);
        fclose(Img);
    
        NV21_T_RGB(Width, Height, NV21_Img, RBG_Img);
        QImage Original_Imag = QImage(RBG_Img, Width, Height, QImage::Format_RGB888);
        QImage Scaled_Img = Original_Imag.scaled(graphicsView->width(), graphicsView->height());
        QGraphicsScene *scene = new QGraphicsScene;
        scene->addPixmap(QPixmap::fromImage(Scaled_Img));
        graphicsView->setScene(scene);
        graphicsView->show();
    
        free(NV21_Img);
        free(RBG_Img);
    }
    

  • Lifetime Qt Champion

    @Haoxinn said in VLD output error:

    File_Path

    C(++) basic - when you allocate something you have to deallocate it later on.
    Don't use c constructs in C++ code. It just gives you problems (like e.g. forgetting about the deallocation).


  • Lifetime Qt Champion

    @Haoxinn said in VLD output error:

    File_Path

    C(++) basic - when you allocate something you have to deallocate it later on.
    Don't use c constructs in C++ code. It just gives you problems (like e.g. forgetting about the deallocation).



  • @Christian-Ehrlicher Thanks for your kindly reply! You mean I should use keywords new and delete to allocate the storage, rather than C function malloc() and free() ?


  • Lifetime Qt Champion

    No, you should use proper container like e.g. std::vector or std::string since the deallocation is done automatically in the dtor of those classes.



  • @Christian-Ehrlicher Ohhhhh! It works! I replaced all the function malloc() in my code, then the output of VLD went back to a normal value. THANKS A LOT!!!


Log in to reply