Skip to content

Commit

Permalink
fix(display): memory leak from X11Surface_SetCaptionW()
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Oct 7, 2019
1 parent 9b4841e commit 484c3d7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/platform/linux/linux_x11display.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,23 @@ static void X11Surface_Resize(LCUI_Surface surface, int width, int height)

static void X11Surface_SetCaptionW(LCUI_Surface surface, const wchar_t *wstr)
{
int len;
size_t len;
char *caption;

LCUI_SurfaceTask task;

task = &surface->tasks[TASK_SET_CAPTION];
X11Surface_ReleaseTask(surface, TASK_SET_CAPTION);
if (wstr) {
char *caption;
len = LCUI_EncodeString(NULL, wstr, 0, ENCODING_UTF8) + 1;
caption = malloc(sizeof(char) * len);
if (!caption) {
return;
}
LCUI_EncodeString(caption, wstr, len, ENCODING_UTF8);
len = LCUI_EncodeString(caption, wstr, len, ENCODING_UTF8);
task->caption = caption;
task->caption_len = len - 1;
task->caption[len] = 0;
task->caption_len = len;
} else {
task->caption = NULL;
task->caption_len = 0;
Expand Down

0 comments on commit 484c3d7

Please sign in to comment.