Skip to content

Commit

Permalink
Merge pull request neutrinolabs#3107 from matt335672/fix_resize_crash
Browse files Browse the repository at this point in the history
Fix GFX resize crash
  • Loading branch information
matt335672 authored Jun 10, 2024
2 parents 8048a63 + 985b0de commit 6fa941e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
28 changes: 21 additions & 7 deletions xrdp/xrdp_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,15 @@ static void
xrdp_enc_data_destructor(void *item, void *closure)
{
XRDP_ENC_DATA *enc = (XRDP_ENC_DATA *)item;
g_free(enc->u.sc.drects);
g_free(enc->u.sc.crects);
if (ENC_IS_BIT_SET(enc->flags, ENC_FLAGS_GFX_BIT))
{
g_free(enc->u.gfx.cmd);
}
else
{
g_free(enc->u.sc.drects);
g_free(enc->u.sc.crects);
}
g_free(enc);
}

Expand Down Expand Up @@ -213,7 +220,8 @@ xrdp_encoder_create(struct xrdp_mm *mm)
g_snprintf(buf, 1024, "xrdp_%8.8x_encoder_event_processed", pid);
self->xrdp_encoder_event_processed = g_create_wait_obj(buf);
g_snprintf(buf, 1024, "xrdp_%8.8x_encoder_term", pid);
self->xrdp_encoder_term = g_create_wait_obj(buf);
self->xrdp_encoder_term_request = g_create_wait_obj(buf);
self->xrdp_encoder_term_done = g_create_wait_obj(buf);
if (client_info->gfx)
{
const char *env_var = g_getenv("XRDP_GFX_FRAMES_IN_FLIGHT");
Expand Down Expand Up @@ -289,8 +297,12 @@ xrdp_encoder_delete(struct xrdp_encoder *self)
return;
}
/* tell worker thread to shut down */
g_set_wait_obj(self->xrdp_encoder_term);
g_sleep(1000);
g_set_wait_obj(self->xrdp_encoder_term_request);
g_obj_wait(&self->xrdp_encoder_term_done, 1, NULL, 0, 5000);
if (!g_is_wait_obj_set(self->xrdp_encoder_term_done))
{
LOG(LOG_LEVEL_WARNING, "Encoder failed to shut down cleanly");
}

#ifdef XRDP_RFXCODEC
for (index = 0; index < 16; index++)
Expand Down Expand Up @@ -323,7 +335,8 @@ xrdp_encoder_delete(struct xrdp_encoder *self)
/* destroy wait objects used for signalling */
g_delete_wait_obj(self->xrdp_encoder_event_to_proc);
g_delete_wait_obj(self->xrdp_encoder_event_processed);
g_delete_wait_obj(self->xrdp_encoder_term);
g_delete_wait_obj(self->xrdp_encoder_term_request);
g_delete_wait_obj(self->xrdp_encoder_term_done);

/* cleanup fifos */
fifo_delete(self->fifo_to_proc, NULL);
Expand Down Expand Up @@ -1406,7 +1419,7 @@ proc_enc_msg(void *arg)
event_to_proc = self->xrdp_encoder_event_to_proc;

term_obj = g_get_term();
lterm_obj = self->xrdp_encoder_term;
lterm_obj = self->xrdp_encoder_term_request;

cont = 1;
while (cont)
Expand Down Expand Up @@ -1457,6 +1470,7 @@ proc_enc_msg(void *arg)
}

} /* end while (cont) */
g_set_wait_obj(self->xrdp_encoder_term_done);
LOG_DEVEL(LOG_LEVEL_DEBUG, "proc_enc_msg: thread exit");
return 0;
}
3 changes: 2 additions & 1 deletion xrdp/xrdp_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct xrdp_encoder
int max_compressed_bytes;
tbus xrdp_encoder_event_to_proc;
tbus xrdp_encoder_event_processed;
tbus xrdp_encoder_term;
tbus xrdp_encoder_term_request;
tbus xrdp_encoder_term_done;
struct fifo *fifo_to_proc;
struct fifo *fifo_processed;
tbus mutex;
Expand Down

0 comments on commit 6fa941e

Please sign in to comment.