mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-11-22 14:35:57 +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_destroy(struct xdpw_screencast_instance *cast);
|
||||
int xdpw_pwr_context_create(struct xdpw_state *state);
|
||||
void xdpw_pwr_context_destroy(struct xdpw_state *state);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -229,6 +229,22 @@ int xdpw_pwr_context_create(struct xdpw_state *state) {
|
|||
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) {
|
||||
if (!cast->stream) {
|
||||
return;
|
||||
|
|
|
@ -474,19 +474,22 @@ int xdpw_screencast_init(struct xdpw_state *state) {
|
|||
int err;
|
||||
err = xdpw_pwr_context_create(state);
|
||||
if (err) {
|
||||
goto end;
|
||||
goto fail_pipewire;
|
||||
}
|
||||
|
||||
err = xdpw_wlr_screencopy_init(state);
|
||||
if (err) {
|
||||
goto end;
|
||||
goto fail_screencopy;
|
||||
}
|
||||
|
||||
return sd_bus_add_object_vtable(state->bus, &slot, object_path, interface_name,
|
||||
screencast_vtable, state);
|
||||
|
||||
end:
|
||||
// TODO: clean up pipewire
|
||||
fail_screencopy:
|
||||
xdpw_wlr_screencopy_finish(&state->screencast);
|
||||
|
||||
fail_pipewire:
|
||||
xdpw_pwr_context_destroy(state);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue