When setting the format on the ViewFinder, a new image_ is allocated.
Any change in format deletes the existing allocation, but it is not
cleaned up on shutdown:
Direct leak of 32 byte(s) in 1 object(s) allocated from:
#0 0x7f0bf8a7e17f in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10e17f)
#1 0x564c7205f7b0 in ViewFinder::setFormat(unsigned int, unsigned int, unsigned int) ../src/qcam/viewfinder.cpp:43
#2 0x564c71fec467 in MainWindow::startCapture() ../src/qcam/main_window.cpp:152
#3 0x564c71fe6c1a in MainWindow::MainWindow(libcamera::CameraManager*, OptionsParser::Options const&) ../src/qcam/main_window.cpp:40
#4 0x564c71fdf133 in main ../src/qcam/main.cpp:76
#5 0x7f0bf5944b6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)
Provide a ViewFinder destructor, and delete the allocation as
appropriate.
Fixes: 97e8b3a2eb ("qcam: Add Qt-based GUI application")
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
52 lines
927 B
C++
52 lines
927 B
C++
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* viewfinder.cpp - qcam - Viewfinder
|
|
*/
|
|
|
|
#include <QImage>
|
|
#include <QPixmap>
|
|
|
|
#include "format_converter.h"
|
|
#include "viewfinder.h"
|
|
|
|
ViewFinder::ViewFinder(QWidget *parent)
|
|
: QLabel(parent), format_(0), width_(0), height_(0), image_(nullptr)
|
|
{
|
|
}
|
|
|
|
ViewFinder::~ViewFinder()
|
|
{
|
|
delete image_;
|
|
}
|
|
|
|
void ViewFinder::display(const unsigned char *raw, size_t size)
|
|
{
|
|
converter_.convert(raw, size, image_);
|
|
|
|
QPixmap pixmap = QPixmap::fromImage(*image_);
|
|
setPixmap(pixmap);
|
|
}
|
|
|
|
int ViewFinder::setFormat(unsigned int format, unsigned int width,
|
|
unsigned int height)
|
|
{
|
|
int ret;
|
|
|
|
ret = converter_.configure(format, width, height);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
format_ = format;
|
|
width_ = width;
|
|
height_ = height;
|
|
|
|
setFixedSize(width, height);
|
|
|
|
delete image_;
|
|
image_ = new QImage(width, height, QImage::Format_RGB32);
|
|
|
|
return 0;
|
|
}
|