From 2b15c4057ea74ac4159c141a82d206a8c5345b21 Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Wed, 4 Apr 2018 22:07:10 +0100 Subject: [PATCH] dtinfo: Fix coverity issues for resource leaks --- .../dtinfo/DtMmdb/btree_berkeley/bt_close.c | 8 +++++-- .../dtinfo/DtMmdb/oliasdb/c_api_book.C | 4 +++- cde/programs/dtinfo/DtMmdb/storage/page.C | 6 +++-- .../dtinfo/DtMmdb/storage/page_storage.C | 4 +++- cde/programs/dtinfo/DtMmdb/utility/string.C | 1 + .../dtinfo/src/Agents/LibraryAgentMotif.C | 3 +++ .../dtinfo/src/Agents/MessageAgentMotif.C | 24 ++++++++++++++----- .../dtinfo/src/Agents/OutlineListViewMotif.C | 5 +++- .../dtinfo/src/OnlineRender/FeatureSupport.C | 3 +++ .../dtinfo/dtinfogen/infolib/etc/SearchPath.C | 1 + .../dtinfo/dtinfogen/infolib/etc/StyleTask.C | 1 + 11 files changed, 47 insertions(+), 13 deletions(-) diff --git a/cde/programs/dtinfo/DtMmdb/btree_berkeley/bt_close.c b/cde/programs/dtinfo/DtMmdb/btree_berkeley/bt_close.c index fc87aa65..bcc39ec1 100644 --- a/cde/programs/dtinfo/DtMmdb/btree_berkeley/bt_close.c +++ b/cde/programs/dtinfo/DtMmdb/btree_berkeley/bt_close.c @@ -172,8 +172,10 @@ __bt_sync(dbp, flags) if (ISSET(t, B_DELCRSR)) { if ((p = (void*)malloc(t->bt_psize)) == NULL) return (RET_ERROR); - if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) + if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) { + free(p); return (RET_ERROR); + } memmove(p, h, t->bt_psize); if ((status = __bt_dleaf(t, h, t->bt_bcursor.index)) == RET_ERROR) @@ -185,8 +187,10 @@ __bt_sync(dbp, flags) CLR(t, B_MODIFIED); ecrsr: if (ISSET(t, B_DELCRSR)) { - if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) + if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) { + free(p); return (RET_ERROR); + } memmove(h, p, t->bt_psize); free(p); mpool_put(t->bt_mp, h, MPOOL_DIRTY); diff --git a/cde/programs/dtinfo/DtMmdb/oliasdb/c_api_book.C b/cde/programs/dtinfo/DtMmdb/oliasdb/c_api_book.C index eaad1804..2fcf00ee 100644 --- a/cde/programs/dtinfo/DtMmdb/oliasdb/c_api_book.C +++ b/cde/programs/dtinfo/DtMmdb/oliasdb/c_api_book.C @@ -191,8 +191,10 @@ DtMmdbHandle** DtMmdbBookGetTabList(DtMmdbInfoRequest* request, unsigned int* le while (*desc != '\0' && *desc != '\t') desc++; - if (*desc != '\t') + if (*desc != '\t') { + free(u); return 0; + } desc++; diff --git a/cde/programs/dtinfo/DtMmdb/storage/page.C b/cde/programs/dtinfo/DtMmdb/storage/page.C index 07daeb5f..d091989c 100644 --- a/cde/programs/dtinfo/DtMmdb/storage/page.C +++ b/cde/programs/dtinfo/DtMmdb/storage/page.C @@ -413,15 +413,17 @@ Boolean page::_alloc_slot( int slot_num, int size, char*& str_ptr ) int new_blank_len = slot_info -> string_leng() ; - if ( new_blank_len < size ) + if ( new_blank_len < size ) { + delete slot_info; return false; + } slot_info -> set_string_ofst( end_ptr ); slot_info -> set_string_leng( size ); slot_info -> set_mode(spointer_t::DELETED, false); slot_info -> set_forward_ptr(0); - delete slot_info; + delete slot_info; if ( slot_num == count() ) { diff --git a/cde/programs/dtinfo/DtMmdb/storage/page_storage.C b/cde/programs/dtinfo/DtMmdb/storage/page_storage.C index 5694eba7..3875ac6b 100644 --- a/cde/programs/dtinfo/DtMmdb/storage/page_storage.C +++ b/cde/programs/dtinfo/DtMmdb/storage/page_storage.C @@ -698,8 +698,10 @@ int page_storage::deleteString(mmdb_pos_t loc, Boolean flush_opt) spointer_t *x = y -> get_spointer(slot_num); - if ( x -> get_mode(spointer_t::DELETED) == true ) + if ( x -> get_mode(spointer_t::DELETED) == true ) { + delete x; return 0; + } loc = x -> forward_ptr(); //debug(cerr, loc); diff --git a/cde/programs/dtinfo/DtMmdb/utility/string.C b/cde/programs/dtinfo/DtMmdb/utility/string.C index e5baf2c5..6057c056 100644 --- a/cde/programs/dtinfo/DtMmdb/utility/string.C +++ b/cde/programs/dtinfo/DtMmdb/utility/string.C @@ -38,6 +38,7 @@ string::string(char* str, int size) string::~string() { + delete sbuf; } char* string::c_str() diff --git a/cde/programs/dtinfo/dtinfo/src/Agents/LibraryAgentMotif.C b/cde/programs/dtinfo/dtinfo/src/Agents/LibraryAgentMotif.C index 23c957dc..dc996b46 100644 --- a/cde/programs/dtinfo/dtinfo/src/Agents/LibraryAgentMotif.C +++ b/cde/programs/dtinfo/dtinfo/src/Agents/LibraryAgentMotif.C @@ -1967,6 +1967,9 @@ LibraryAgent::transferCB(Widget w, XtPointer client_data, XtPointer call_data) file = strdup(netfile); if (file == NULL || *file == '\0') { + if(file) { + tt_free(file); + } XtFree(netfile); XmTransferDone(cs->transfer_id, XmTRANSFER_DONE_FAIL); return; diff --git a/cde/programs/dtinfo/dtinfo/src/Agents/MessageAgentMotif.C b/cde/programs/dtinfo/dtinfo/src/Agents/MessageAgentMotif.C index 510ae98f..2f3d85f0 100644 --- a/cde/programs/dtinfo/dtinfo/src/Agents/MessageAgentMotif.C +++ b/cde/programs/dtinfo/dtinfo/src/Agents/MessageAgentMotif.C @@ -202,8 +202,10 @@ void MessageAgent::displayMessage (char *message_text) { char *message_string = strdup(message_text); - if(f_dialog == NULL) + if(f_dialog == NULL) { + free(message_string); return; + } XmStringLocalized mtfstring; @@ -245,8 +247,10 @@ MessageAgent::displayError (char *message_text, Widget parent) char *message_string = strdup(message_text); if (f_dialog == NULL) create_ui(parent); - if (g_active) + if (g_active) { + free(message_string); return; + } g_active = TRUE; // Set the window title @@ -282,8 +286,10 @@ MessageAgent::displayWarning (char *message_text, Widget parent) char *message_string = strdup(message_text); if (f_dialog == NULL) create_ui(parent); - if (g_active) + if (g_active) { + free(message_string); return; + } g_active = TRUE; // Set the window title @@ -319,8 +325,10 @@ MessageAgent::displayInformation (char *message_text, Widget parent) if (f_dialog == NULL) create_ui(parent); - if (g_active) + if (g_active) { + free(message_string); return; + } g_active = TRUE; // Set the window title @@ -433,8 +441,10 @@ MessageAgent::displayQuestion (char *message_text, Widget parent) if (f_dialog == NULL) create_ui(parent); - if (g_active) + if (g_active) { + free(message_string); return (FALSE); + } g_active = TRUE; // Set the window title @@ -485,8 +495,10 @@ MessageAgent::displayQuit (char *message_text, Widget parent) if (f_dialog == NULL) create_ui(parent); - if (g_active) + if (g_active) { + free(message_string); return; + } g_active = TRUE; // Set the window title diff --git a/cde/programs/dtinfo/dtinfo/src/Agents/OutlineListViewMotif.C b/cde/programs/dtinfo/dtinfo/src/Agents/OutlineListViewMotif.C index 5abb7405..fdadc0a0 100644 --- a/cde/programs/dtinfo/dtinfo/src/Agents/OutlineListViewMotif.C +++ b/cde/programs/dtinfo/dtinfo/src/Agents/OutlineListViewMotif.C @@ -818,10 +818,11 @@ a human readable character string. static void OutputAnAtomName(Widget w, Atom target) { - char *AtomName = (char *)malloc(sizeof(char *) * 34); + char *AtomName = NULL; AtomName = XGetAtomName(XtDisplay(w), target); printf("\t%s\n", AtomName); + XFree(AtomName); } // ///////////////////////////////////////////////////////////////// @@ -934,12 +935,14 @@ OutlineListView::printConvertCallback(WCallback *wcb) // write out the locator if (fputs(((TOC_Element *)te)->toc()->locator(), fp) == EOF) { fprintf(stderr, "Cannot write file %s in current directory.\n", filepath); + fclose(fp); return; } // write out eol if (fputs("\n", fp) == EOF) { fprintf(stderr, "Cannot write file %s in current directory.\n", filepath); + fclose(fp); return; } diff --git a/cde/programs/dtinfo/dtinfo/src/OnlineRender/FeatureSupport.C b/cde/programs/dtinfo/dtinfo/src/OnlineRender/FeatureSupport.C index 59cb6040..c846c986 100644 --- a/cde/programs/dtinfo/dtinfo/src/OnlineRender/FeatureSupport.C +++ b/cde/programs/dtinfo/dtinfo/src/OnlineRender/FeatureSupport.C @@ -398,6 +398,7 @@ pattern_done: printf("pattern = %s.\n", pattern); #endif xlfd = strdup(pattern); + free(dupfallback); return(xlfd); } @@ -456,6 +457,8 @@ pattern_done: #ifdef FONT_DEBUG printf("xlfd = %s.\n", xlfd); #endif + + free(dupfallback); return(xlfd); } diff --git a/cde/programs/dtinfo/dtinfogen/infolib/etc/SearchPath.C b/cde/programs/dtinfo/dtinfogen/infolib/etc/SearchPath.C index e33ed643..1323505e 100644 --- a/cde/programs/dtinfo/dtinfogen/infolib/etc/SearchPath.C +++ b/cde/programs/dtinfo/dtinfogen/infolib/etc/SearchPath.C @@ -149,6 +149,7 @@ SearchPath::get_real_path( const char *file_name ) fclose( fp ); return ( full_path_name ); } + fclose( fp ); } return NULL; diff --git a/cde/programs/dtinfo/dtinfogen/infolib/etc/StyleTask.C b/cde/programs/dtinfo/dtinfogen/infolib/etc/StyleTask.C index 7c07b3eb..6970bcf0 100644 --- a/cde/programs/dtinfo/dtinfogen/infolib/etc/StyleTask.C +++ b/cde/programs/dtinfo/dtinfogen/infolib/etc/StyleTask.C @@ -533,6 +533,7 @@ void StyleTask::write_record( void ) else { Token::signalError(Token::User, Token::Continuable, 0, 0, "Duplicate stylesheet id `%s'", localstr); + delete bogus; return; } -- 2.25.1