gstreamer: allocator: gst_libcamera_allocator_new(): Fix memory leak
If `FrameBufferAllocator::allocate()` causes the construction to be aborted, the allocated `GstLibcameraAllocator` will not be deallocated properly. Use `g_autoptr()` to address this. `g_steal_pointer()` could only be used in glib 2.68 or later because earlier it evaluates to a pointer-to-void in C++, which would necessitate a `static_cast`. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
This commit is contained in:
parent
fd6e41b9fb
commit
ac611e80d2
1 changed files with 6 additions and 6 deletions
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#include "gstlibcameraallocator.h"
|
#include "gstlibcameraallocator.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <libcamera/camera.h>
|
#include <libcamera/camera.h>
|
||||||
#include <libcamera/framebuffer_allocator.h>
|
#include <libcamera/framebuffer_allocator.h>
|
||||||
#include <libcamera/stream.h>
|
#include <libcamera/stream.h>
|
||||||
|
@ -199,15 +201,13 @@ GstLibcameraAllocator *
|
||||||
gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,
|
gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,
|
||||||
CameraConfiguration *config_)
|
CameraConfiguration *config_)
|
||||||
{
|
{
|
||||||
auto *self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,
|
g_autoptr(GstLibcameraAllocator) self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,
|
||||||
nullptr));
|
nullptr));
|
||||||
gint ret;
|
gint ret;
|
||||||
|
|
||||||
self->cm_ptr = new std::shared_ptr<CameraManager>(gst_libcamera_get_camera_manager(ret));
|
self->cm_ptr = new std::shared_ptr<CameraManager>(gst_libcamera_get_camera_manager(ret));
|
||||||
if (ret) {
|
if (ret)
|
||||||
g_object_unref(self);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
self->fb_allocator = new FrameBufferAllocator(camera);
|
self->fb_allocator = new FrameBufferAllocator(camera);
|
||||||
for (StreamConfiguration &streamCfg : *config_) {
|
for (StreamConfiguration &streamCfg : *config_) {
|
||||||
|
@ -228,7 +228,7 @@ gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,
|
||||||
g_hash_table_insert(self->pools, stream, pool);
|
g_hash_table_insert(self->pools, stream, pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return std::exchange(self, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue