mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-11-26 07:55:58 +01:00
screencast: improve cleanup on error in xdpw_screencast_init()
- currently the cleanup can segfault due to uninitialized list objects - introduce xdpw_pwr_context_destroy() and fixup goto logic
This commit is contained in:
parent
d2fa4aa5e7
commit
f60bdcef71
3 changed files with 24 additions and 4 deletions
|
@ -9,5 +9,6 @@
|
||||||
void xdpw_pwr_stream_create(struct xdpw_screencast_instance *cast);
|
void xdpw_pwr_stream_create(struct xdpw_screencast_instance *cast);
|
||||||
void xdpw_pwr_stream_destroy(struct xdpw_screencast_instance *cast);
|
void xdpw_pwr_stream_destroy(struct xdpw_screencast_instance *cast);
|
||||||
int xdpw_pwr_context_create(struct xdpw_state *state);
|
int xdpw_pwr_context_create(struct xdpw_state *state);
|
||||||
|
void xdpw_pwr_context_destroy(struct xdpw_state *state);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -229,6 +229,22 @@ int xdpw_pwr_context_create(struct xdpw_state *state) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xdpw_pwr_context_destroy(struct xdpw_state *state) {
|
||||||
|
struct xdpw_screencast_context *ctx = &state->screencast;
|
||||||
|
|
||||||
|
logprint(DEBUG, "pipewire: disconnecting fom core");
|
||||||
|
|
||||||
|
if (ctx->core) {
|
||||||
|
pw_core_disconnect(ctx->core);
|
||||||
|
ctx->core = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->pwr_context) {
|
||||||
|
pw_context_destroy(ctx->pwr_context);
|
||||||
|
ctx->pwr_context = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void xdpw_pwr_stream_destroy(struct xdpw_screencast_instance *cast) {
|
void xdpw_pwr_stream_destroy(struct xdpw_screencast_instance *cast) {
|
||||||
if (!cast->stream) {
|
if (!cast->stream) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -474,19 +474,22 @@ int xdpw_screencast_init(struct xdpw_state *state) {
|
||||||
int err;
|
int err;
|
||||||
err = xdpw_pwr_context_create(state);
|
err = xdpw_pwr_context_create(state);
|
||||||
if (err) {
|
if (err) {
|
||||||
goto end;
|
goto fail_pipewire;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = xdpw_wlr_screencopy_init(state);
|
err = xdpw_wlr_screencopy_init(state);
|
||||||
if (err) {
|
if (err) {
|
||||||
goto end;
|
goto fail_screencopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sd_bus_add_object_vtable(state->bus, &slot, object_path, interface_name,
|
return sd_bus_add_object_vtable(state->bus, &slot, object_path, interface_name,
|
||||||
screencast_vtable, state);
|
screencast_vtable, state);
|
||||||
|
|
||||||
end:
|
fail_screencopy:
|
||||||
// TODO: clean up pipewire
|
|
||||||
xdpw_wlr_screencopy_finish(&state->screencast);
|
xdpw_wlr_screencopy_finish(&state->screencast);
|
||||||
|
|
||||||
|
fail_pipewire:
|
||||||
|
xdpw_pwr_context_destroy(state);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue