From 7c05a7f7b42eabbad4ff52373b73321115caa559 Mon Sep 17 00:00:00 2001 From: raghu447 Date: Mon, 15 Jun 2020 12:01:19 +0530 Subject: [PATCH] libcamera: fixed a small leak and double free --- spa/plugins/libcamera/libcamera-client.c | 1 - spa/plugins/libcamera/libcamera-source.c | 1 - spa/plugins/libcamera/libcamera_wrapper.cpp | 19 ++++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/spa/plugins/libcamera/libcamera-client.c b/spa/plugins/libcamera/libcamera-client.c index f5d755222..81b59b9d5 100644 --- a/spa/plugins/libcamera/libcamera-client.c +++ b/spa/plugins/libcamera/libcamera-client.c @@ -162,7 +162,6 @@ static int impl_clear(struct spa_handle *handle) if(this->dev.camera) { deleteLibCamera(this->dev.camera); - free(this->dev.camera); this->dev.camera = NULL; } return 0; diff --git a/spa/plugins/libcamera/libcamera-source.c b/spa/plugins/libcamera/libcamera-source.c index 31f8c4af1..e3720e3f0 100644 --- a/spa/plugins/libcamera/libcamera-source.c +++ b/spa/plugins/libcamera/libcamera-source.c @@ -900,7 +900,6 @@ static int impl_clear(struct spa_handle *handle) if(port->dev.camera) { deleteLibCamera(port->dev.camera); - free(port->dev.camera); port->dev.camera = NULL; } if(this->have_source) { diff --git a/spa/plugins/libcamera/libcamera_wrapper.cpp b/spa/plugins/libcamera/libcamera_wrapper.cpp index fef4c7a88..92302f041 100644 --- a/spa/plugins/libcamera/libcamera_wrapper.cpp +++ b/spa/plugins/libcamera/libcamera_wrapper.cpp @@ -529,6 +529,16 @@ extern "C" { void LibCamera::stop() { this->disconnect(); + uint32_t bufIdx = 0; + StreamConfiguration &cfg = this->config_->at(0); + Stream *stream = cfg.stream(); + + for (const std::unique_ptr &buffer : this->allocator_->buffers(stream)) { + delete [] this->fd_[bufIdx]; + bufIdx++; + } + delete [] this->fd_; + spa_log_info(this->log_, "Stopping camera ..."); this->cam_->stop(); if(this->allocator_) { @@ -536,15 +546,6 @@ extern "C" { this->allocator_ = nullptr; } - if(this->fd_) { - for(uint32_t i = 0; i < this->nplanes_; i++) { - delete this->fd_[i]; - this->fd_[i] = nullptr; - } - delete this->fd_; - this->fd_ = nullptr; - } - this->item_free_fn(); }