diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c index e108ff33b0..deafc77dbe 100644 --- a/xrdp/xrdp_mm.c +++ b/xrdp/xrdp_mm.c @@ -1191,6 +1191,7 @@ xrdp_mm_egfx_caps_advertise(void *user, int caps_count, { LOG(LOG_LEVEL_INFO, "xrdp_mm_egfx_caps_advertise: can not do gfx"); } + /* create copy for sorting */ ver_flags = g_new(struct _ver_flags, caps_count); if (ver_flags == NULL) { @@ -1201,6 +1202,7 @@ xrdp_mm_egfx_caps_advertise(void *user, int caps_count, ver_flags[index].version = versions[index]; ver_flags[index].flags = flagss[index]; } + /* sort */ g_qsort(ver_flags, caps_count, sizeof(struct _ver_flags), cmpverfunc); best_index = -1; best_h264_index = -1; @@ -1253,7 +1255,6 @@ xrdp_mm_egfx_caps_advertise(void *user, int caps_count, break; } } - g_free(ver_flags); if (best_pro_index >= 0) { best_index = best_pro_index; @@ -1269,10 +1270,10 @@ xrdp_mm_egfx_caps_advertise(void *user, int caps_count, if (best_index >= 0) { LOG(LOG_LEVEL_INFO, " replying version 0x%8.8x flags 0x%8.8x", - versions[best_index], flagss[best_index]); + ver_flags[best_index].version, ver_flags[best_index].flags); error = xrdp_egfx_send_capsconfirm(self->egfx, - versions[best_index], - flagss[best_index]); + ver_flags[best_index].version, + ver_flags[best_index].flags); LOG(LOG_LEVEL_INFO, "xrdp_mm_egfx_caps_advertise: xrdp_egfx_send_capsconfirm " "error %d", error); error = xrdp_egfx_send_reset_graphics(self->egfx, @@ -1316,6 +1317,7 @@ xrdp_mm_egfx_caps_advertise(void *user, int caps_count, self->encoder = xrdp_encoder_create(self); xrdp_bitmap_invalidate(screen, &lrect); } + g_free(ver_flags); return 0; }