dthelp: Further coverity fixes
[oweals/cde.git] / cde / programs / dthelp / dthelpprint / PrintTopics.c
index 35e4d0f25a4f4129033746c6c25cc0b198b77b94..c5a609951de13f28e511d7d604818c100466bf36 100644 (file)
@@ -1,3 +1,25 @@
+/*
+ * CDE - Common Desktop Environment
+ *
+ * Copyright (c) 1993-2012, The Open Group. All rights reserved.
+ *
+ * These libraries and programs are free software; you can
+ * redistribute them and/or modify them under the terms of the GNU
+ * Lesser General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * These libraries and programs are distributed in the hope that
+ * they will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with these libraries and programs; if not, write
+ * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ * Floor, Boston, MA 02110-1301 USA
+ */
 #if DOC
 /*===================================================================
 $FILEBEG$:   PrintTopics.c
@@ -39,6 +61,7 @@ $COPYRIGHT$:
 #endif
 #include <errno.h>
 
+#include <time.h>
 
 #include "HelpPrintI.h"  /* helpprint */
 
@@ -989,6 +1012,8 @@ int DoStrColsWidth(
       wcstr[--wclen] = EOS;
    wcstombs(str,wcstr,len+1);
 
+   free(wcstr);
+
    return wclen;
 }       /*$END$*/
 
@@ -1068,6 +1093,9 @@ void GenHeadFootFormatArgs(
        /* put into state data */
        state->hffArgs.volumeDate = strdup(buf);
        state->hffArgs.volumeDateColsWidth = width;
+       
+       free(locDocId);
+       free(locDateStamp);
     }
 
     /* get today's date */
@@ -1332,7 +1360,7 @@ int PrintHeadFootStr(
     free(formattedStr);
 
     /*** output the str ***/
-    fprintf(topicsFP,buf);
+    fprintf(topicsFP, "%s", buf);
 
     return lineCnt;
 }       /*$END$*/
@@ -1726,6 +1754,8 @@ int ProcessSubTopics(
    /* if processing subtopics, reset subsection number */
    if(subSectNumIndex > 1) state->sectNums[subSectNumIndex] = 0;
    state->level = level;       /* state->level was modified by the FOR loop */
+
+   free(children);
    return ret;
 }
 
@@ -2243,13 +2273,11 @@ int ProcessTopics(
    /* if processing subtopics, start processing at the top */
    if ( processSubTopics )
    {
-      char * name = NULL;
       int    offset;
 
       /* get the top topic of the volume */
       ret = _DtHelpCeGetTopTopicId(state->volHandle, &state->currentLocId);
       if (ret != True) state->currentLocId = strdup("_HOMETOPIC");
-      if(name) free(name);
    }
    else
    {   /* otherwise, process only where needed */
@@ -2383,7 +2411,7 @@ int DoHelpTopicsProcessing(
    char *      buf;
    char *      start;
    char *      next;
-   char *      pgbrkFile;
+   char *      pgbrkFile = NULL;
    char *      partFiles[NUMPARTS];
    Boolean     validFile = False;
 
@@ -2462,9 +2490,10 @@ int DoHelpTopicsProcessing(
    /* only do the operation if there are valid files */
    if (validFile)
    {
+      int rv;
       sprintf(next,"> %s", *ret_resultsFile);
       if(options->debugHelpPrint) printf("%s\n",buf);
-      system(buf);
+      rv = system(buf);
    }
    free(buf);
    ret = 0;
@@ -2483,7 +2512,10 @@ cleanup:
         unlink(partFiles[i]); 
         free(partFiles[i]);
      }
-   unlink(pgbrkFile);
+
+   if(pgbrkFile) { 
+     unlink(pgbrkFile);
+   }
 
    /* NOTE: should free Toc here if interested in no leaks */