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:
Tobias Jakobi 2021-05-09 13:44:10 +02:00 committed by Simon Ser
parent d2fa4aa5e7
commit f60bdcef71
3 changed files with 24 additions and 4 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;
}