dtinfo: Fix coverity issues for resource leaks
authorPeter Howkins <flibble@users.sf.net>
Wed, 4 Apr 2018 21:07:10 +0000 (22:07 +0100)
committerPeter Howkins <flibble@users.sf.net>
Wed, 4 Apr 2018 21:07:10 +0000 (22:07 +0100)
cde/programs/dtinfo/DtMmdb/btree_berkeley/bt_close.c
cde/programs/dtinfo/DtMmdb/oliasdb/c_api_book.C
cde/programs/dtinfo/DtMmdb/storage/page.C
cde/programs/dtinfo/DtMmdb/storage/page_storage.C
cde/programs/dtinfo/DtMmdb/utility/string.C
cde/programs/dtinfo/dtinfo/src/Agents/LibraryAgentMotif.C
cde/programs/dtinfo/dtinfo/src/Agents/MessageAgentMotif.C
cde/programs/dtinfo/dtinfo/src/Agents/OutlineListViewMotif.C
cde/programs/dtinfo/dtinfo/src/OnlineRender/FeatureSupport.C
cde/programs/dtinfo/dtinfogen/infolib/etc/SearchPath.C
cde/programs/dtinfo/dtinfogen/infolib/etc/StyleTask.C

index fc87aa6564ec36cd3e23fa7a9b51cf3787e92618..bcc39ec18c5aeeebfedbd295633196eda2b815b3 100644 (file)
@@ -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);
index eaad18045841f13b77fb69aaeabedca0ff4262fc..2fcf00eea24e5a95c987bd9d011e954e98eb1c3f 100644 (file)
@@ -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++;
 
index 07daeb5ff158af99db4a407a5065ccf289b00d65..d091989c8cdee34537de3f7fccb138e78aefcf31 100644 (file)
@@ -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() ) {
 
index 5694eba736d5a6790328f82e4ef0d0d4e99436e2..3875ac6b3a64df89cb0cd9d016b0e79f737e8795 100644 (file)
@@ -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);
index e5baf2c570966243f581d696bc2157b1d3127bb6..6057c05646e973100aed28cf358e7ec53f4f1ab2 100644 (file)
@@ -38,6 +38,7 @@ string::string(char* str, int size)
 
 string::~string()
 {
+   delete sbuf;
 }
 
 char* string::c_str()
index 23c957dcf65898d7dc17bceb514385b799a7ea90..dc996b469177da46b9be0cdc0754d2af38037d6f 100644 (file)
@@ -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;
index 510ae98f3fcb34b632cf89a6b6d83aefc3cebba2..2f3d85f0edfa47ae1917d36aca9436d871f9b0f2 100644 (file)
@@ -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
index 5abb7405178d7d2b4965788f09da738e15b95c39..fdadc0a09219d2d597e3b2260343dfcbf3ecdfe3 100644 (file)
@@ -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;
            }
            
index 59cb604017cd2b8031bffff12b7d8d9cd49ddb8b..c846c986d9141eabf6f7f6c9742b6b5cccdaf123 100644 (file)
@@ -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);
                              
 }
index e33ed643527ca7d91b5a0d7b7f73aaf1eb960467..1323505e735c29e35dee931e423d74a1aa071525 100644 (file)
@@ -149,6 +149,7 @@ SearchPath::get_real_path( const char *file_name )
       fclose( fp );
       return ( full_path_name );
     }
+    fclose( fp );
   }
 
   return NULL;
index 7c07b3eb026cd0b854430ec5006cd5d676195a5f..6970bcf0b68beef878254cba6e17465287bf7f6e 100644 (file)
@@ -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;
    }