mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
libcamera: fix a use-after-free due an attempt to stop the camera twice
Camera is currently stopped and started in the spa_libcamera_set_format()
function, but this leads to a segfault due attempting to access a buffers
field of an already freed libcamera::FrameBufferAllocator instance.
The FrameBufferAllocator instance is freed in LibCamera::stop(), that is
called by spa_libcamera_stream_off() as handler of the node commands
SPA_NODE_COMMAND_Pause and SPA_NODE_COMMAND_Suspend.
Since the camera was already stopped, there's no need to attempt to stop
it again. In fact, the camera shouldn't be stopped/started at all in the
spa_libcamera_set_format() function but instead only as an action of the
SPA_NODE_COMMAND_{Pause,Suspend} and SPA_NODE_COMMAND_Start commands.
And same for the stop that's done in the LibCamera::close() function, it
shouldn't be needed because the camera is already stopped before closing.
Fixes #1513
This commit is contained in:
parent
a7a6f19815
commit
21c412dc49
2 changed files with 2 additions and 7 deletions
|
|
@ -470,9 +470,6 @@ static int spa_libcamera_set_format(struct impl *this, struct spa_video_info *fo
|
||||||
if ((res = spa_libcamera_open(dev)) < 0)
|
if ((res = spa_libcamera_open(dev)) < 0)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
/* stop the camera first. It might have opened with different configuration*/
|
|
||||||
libcamera_stop_capture(dev->camera);
|
|
||||||
|
|
||||||
spa_log_info(dev->log, "libcamera: set %s %dx%d %d/%d\n", (char *)&info->fourcc,
|
spa_log_info(dev->log, "libcamera: set %s %dx%d %d/%d\n", (char *)&info->fourcc,
|
||||||
fmt.width, fmt.height,
|
fmt.width, fmt.height,
|
||||||
fmt.denominator, fmt.numerator);
|
fmt.denominator, fmt.numerator);
|
||||||
|
|
@ -485,9 +482,6 @@ static int spa_libcamera_set_format(struct impl *this, struct spa_video_info *fo
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* start the camera now with the configured params */
|
|
||||||
libcamera_start_capture(dev->camera);
|
|
||||||
|
|
||||||
dev->have_format = true;
|
dev->have_format = true;
|
||||||
size->width = libcamera_get_streamcfg_width(dev->camera);
|
size->width = libcamera_get_streamcfg_width(dev->camera);
|
||||||
size->height = libcamera_get_streamcfg_height(dev->camera);
|
size->height = libcamera_get_streamcfg_height(dev->camera);
|
||||||
|
|
@ -871,6 +865,8 @@ static int spa_libcamera_stream_on(struct impl *this)
|
||||||
|
|
||||||
libcamera_connect(dev->camera);
|
libcamera_connect(dev->camera);
|
||||||
|
|
||||||
|
libcamera_start_capture(dev->camera);
|
||||||
|
|
||||||
port->source.func = libcamera_on_fd_events;
|
port->source.func = libcamera_on_fd_events;
|
||||||
port->source.data = this;
|
port->source.data = this;
|
||||||
port->source.fd = spa_system_eventfd_create(this->system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
|
port->source.fd = spa_system_eventfd_create(this->system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
|
||||||
|
|
|
||||||
|
|
@ -540,7 +540,6 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibCamera::close() {
|
void LibCamera::close() {
|
||||||
this->stop();
|
|
||||||
this->cam_->release();
|
this->cam_->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue