From b86eff35f033174a25dd7fa1a70b306ba404e14e Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Sun, 14 Dec 2025 11:54:14 +0100 Subject: [PATCH] Fix memory leaks --- cde/lib/DtHelp/AccessSDL.c | 37 +++++++++++----------- cde/programs/dtcreate/cmnutils.c | 1 + cde/programs/dtmail/dtmail/WMSaveSession.C | 4 +++ cde/programs/dtmail/dtmailpr/message.C | 20 +++++------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/cde/lib/DtHelp/AccessSDL.c b/cde/lib/DtHelp/AccessSDL.c index e770782ac..8582f340e 100644 --- a/cde/lib/DtHelp/AccessSDL.c +++ b/cde/lib/DtHelp/AccessSDL.c @@ -1359,35 +1359,34 @@ _DtHelpCeGetSdlDocStamp( char **ret_time) { int result = -1; - char *docId = NULL; - char *timestamp = NULL; CESDLVolume *sdlVol = _DtHelpCeGetSdlVolumePtr(volume); if (sdlVol->sdl_info != NULL) { result = 0; - if (NULL != _SdlDocInfoPtrDocId(sdlVol->sdl_info)) - docId = strdup(_SdlDocInfoPtrDocId(sdlVol->sdl_info)); - else + char *tmp = _SdlDocInfoPtrDocId(sdlVol->sdl_info); + if (NULL != tmp) { + if (ret_doc != NULL) { + *ret_doc = strdup(tmp); + if (*ret_doc == NULL) + return -1; + } + } else { result = -2; + } - if (NULL != _SdlDocInfoPtrStamp(sdlVol->sdl_info)) - timestamp = strdup(_SdlDocInfoPtrStamp(sdlVol->sdl_info)); - else + tmp = _SdlDocInfoPtrStamp(sdlVol->sdl_info); + if (NULL != tmp) { + if (ret_time != NULL) { + *ret_time = strdup(tmp); + if (*ret_time == NULL) + return -1; + } + } else { result = -2; + } } - if (ret_doc != NULL) - *ret_doc = docId; - if (ret_time != NULL) - *ret_time = timestamp; - - if (result == 0 && (docId == NULL || timestamp == NULL)) { - free(docId); /* Incase only one of them is NULL */ - free(timestamp); /* " */ - return -1; - } - return result; } diff --git a/cde/programs/dtcreate/cmnutils.c b/cde/programs/dtcreate/cmnutils.c index 6d0945be0..cc9709641 100644 --- a/cde/programs/dtcreate/cmnutils.c +++ b/cde/programs/dtcreate/cmnutils.c @@ -95,6 +95,7 @@ text_string = (char *)calloc (1, sizeof (char)); if (xmstring) { if (!XmStringInitContext (&context, xmstring)) { printf("Can't convert compound string.\n"); + free(text_string); return (NULL); } while (XmStringGetNextSegment (context, &temp, &charset, diff --git a/cde/programs/dtmail/dtmail/WMSaveSession.C b/cde/programs/dtmail/dtmail/WMSaveSession.C index 04cf03764..09aba5e41 100644 --- a/cde/programs/dtmail/dtmail/WMSaveSession.C +++ b/cde/programs/dtmail/dtmail/WMSaveSession.C @@ -373,6 +373,7 @@ RoamMenuWindow::restoreSession(char *buf) { fscanf(fp,"%s[\n]",buf); LOG_CLOSEFILEPTR(log); + delete [] workspaces; return NULL; } @@ -472,6 +473,7 @@ RoamMenuWindow::restoreSession(char *buf) rmw->manage(); } + delete [] workspaces; LOG_CLOSEFILEPTR(log); return rmw; } @@ -594,6 +596,7 @@ SendMsgDialog::restoreSession(char *buf) { fscanf(fp,"%s[\n]",buf); LOG_CLOSEFILEPTR(log); + delete [] workspaces; return; } @@ -671,6 +674,7 @@ SendMsgDialog::restoreSession(char *buf) smd->manage(); } + delete [] workspaces; LOG_CLOSEFILEPTR(log); } diff --git a/cde/programs/dtmail/dtmailpr/message.C b/cde/programs/dtmail/dtmailpr/message.C index 4f6aea694..884f85f9e 100644 --- a/cde/programs/dtmail/dtmailpr/message.C +++ b/cde/programs/dtmail/dtmailpr/message.C @@ -313,6 +313,7 @@ DmxMsg::display (void) env.logError(DTM_FALSE, "DEBUG dtmailpr: v3_cs = %s\n", v3_cs); #endif } + delete [] v3_cs; to_cs = firstPart->locToConvName(); #ifdef DEBUG @@ -358,16 +359,11 @@ DmxMsg::display (void) if (converted && contents) free(contents); - char *numbuf = new char [10241]; - memset (numbuf, 0, 1024); - -#ifdef NEVER - // Don't want "Message 1:" appearing in print output - sprintf (numbuf, "Messsage %s:\n%s\n", - addlInfo, printHeader (MSGHEADER)); -#endif - puts(printHeader(MSGHEADER)); + char *msgh = printHeader(MSGHEADER); + puts(msgh); puts(buf); + delete [] buf; + delete [] msgh; fflush(stdout); @@ -418,12 +414,12 @@ DmxMsg::display (void) printf ("[%d] \"%s\"%s, ", i, name, description); printf ("%s, %lu bytes\n", type, length); - if (attbuf != NULL) + if (attbuf != NULL) { delete [] attbuf; - + attbuf = NULL; + } } - delete [] v3_cs; return; }