From 1854700722db8067460e82a711521fdb27fb51d4 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 3 Jan 2018 01:31:52 +0100 Subject: Font.c: replace malloc + strcpy by strdup + fix memleak --- nx-X11/programs/Xserver/hw/nxagent/Font.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'nx-X11/programs/Xserver') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Font.c b/nx-X11/programs/Xserver/hw/nxagent/Font.c index 197f0c84a..5af88b137 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Font.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Font.c @@ -334,10 +334,12 @@ void nxagentListRemoteAddName(const char *name, int status) if ((nxagentRemoteFontList.list[pos] = malloc(sizeof(nxagentFontRec)))) { - nxagentRemoteFontList.list[pos]->name = malloc(strlen(name) +1); + nxagentRemoteFontList.list[pos]->name = strdup(name); if (nxagentRemoteFontList.list[pos]->name == NULL) { fprintf(stderr, "Font: remote list name memory allocation failed!.\n"); + free(nxagentRemoteFontList.list[pos]); + nxagentRemoteFontList.list[pos] = NULL; return; } } @@ -346,7 +348,6 @@ void nxagentListRemoteAddName(const char *name, int status) fprintf(stderr, "Font: remote list record memory allocation failed!.\n"); return; } - strcpy(nxagentRemoteFontList.list[pos]->name,name); nxagentRemoteFontList.list[pos]->status = status; nxagentRemoteFontList.length++; -- cgit v1.2.3