butc: avoid freeing uninitialized pointer in writeDbDump()
[openafs.git] / src / butc / tcudbprocs.c
index e51625c..3fe76f5 100644 (file)
 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
 #endif
 
-#include <sys/types.h>
-#ifdef HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#include <io.h>
-#else
-#include <sys/time.h>
-#include <sys/file.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#endif
-#include <errno.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <afs/afsint.h>
-#include <stdio.h>
-#include <string.h>
-#include <afs/procmgmt.h>
 #include <afs/afs_assert.h>
 #include <afs/prs_fs.h>
-#include <fcntl.h>
 #include <afs/nfs.h>
 #include <lwp.h>
 #include <lock.h>
@@ -57,6 +39,7 @@
 #include <afs/butm_prototypes.h>
 #include <afs/budb_prototypes.h>
 #include <afs/afsutil.h>
+
 #include "butc_internal.h"
 #include "error_macros.h"
 
@@ -142,7 +125,6 @@ GetDBTape(afs_int32 taskId, Date expires, struct butm_tapeInfo *tapeInfoPtr,
     char tapeName[BU_MAXTAPELEN];
     char strlevel[5];
     struct timeval tp;
-    struct timezone tzp;
     afs_int32 curTime;
     int tapecount = 1;
 
@@ -256,7 +238,7 @@ GetDBTape(afs_int32 taskId, Date expires, struct butm_tapeInfo *tapeInfoPtr,
             */
            else {
                /* Check the tape's expiration date. Use the expiration on the label */
-               gettimeofday(&tp, &tzp);
+               gettimeofday(&tp, NULL);
                curTime = tp.tv_sec;
                if (curTime < oldTapeLabel.expirationDate) {
                    TLog(taskId, "This tape has not expired\n");
@@ -433,6 +415,8 @@ writeDbDump(struct butm_tapeInfo *tapeInfoPtr, afs_uint32 taskId,
     extern struct tapeConfig globalTapeConfig;
     extern struct udbHandleS udbHandle;
 
+    charList.charListT_val = 0;
+    charList.charListT_len = 0;
     blockSize = BUTM_BLKSIZE;
     writeBlock = (char *)malloc(BUTM_BLOCKSIZE);
     if (!writeBlock)
@@ -463,8 +447,6 @@ writeDbDump(struct butm_tapeInfo *tapeInfoPtr, afs_uint32 taskId,
     writeBufPtr = &writeBuffer[0];
     firstcall = 1;
     sequence = 1;
-    charList.charListT_val = 0;
-    charList.charListT_len = 0;
 
     while (1) {                        /*w */
        /* When no data in buffer, read data from the budb_server */
@@ -646,7 +628,7 @@ void *
 saveDbToTape(void *param)
 {
     struct saveDbIf *saveDbIfPtr = (struct saveDbIf *)param;
-    afs_int32 code = 0;
+    afs_int32 code;
     afs_int32 i;
     int wroteLabel;
     afs_uint32 taskId;
@@ -658,8 +640,10 @@ saveDbToTape(void *param)
     extern struct deviceSyncNode *deviceLatch;
     extern struct tapeConfig globalTapeConfig;
 
+    afs_pthread_setname_self("Db save");
     expires = (saveDbIfPtr->archiveTime ? NEVERDATE : 0);
     taskId = saveDbIfPtr->taskId;
+    dumpEntry.id = 0;
 
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);     /* lock tape device */
@@ -1040,6 +1024,7 @@ restoreDbFromTape(void *param)
     extern struct tapeConfig globalTapeConfig;
     extern struct deviceSyncNode *deviceLatch;
 
+    afs_pthread_setname_self("Db restore");
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);     /* lock tape device */
     clearStatus(taskId, DRIVE_WAIT);
@@ -1137,6 +1122,7 @@ KeepAlive(void *unused)
 
     extern struct udbHandleS udbHandle;
 
+    afs_pthread_setname_self("Keep-alive");
     while (1) {
 #ifdef AFS_PTHREAD_ENV
        sleep(5);
@@ -1455,11 +1441,7 @@ restoreText(struct butm_tapeInfo *tapeInfo,
 
     /* open the text file */
     sprintf(filename, "%s/bu_XXXXXX", gettmpdir());
-#if defined (HAVE_MKSTEMP)
     fid = mkstemp(filename);
-#else
-    fid = open(mktemp(filename), O_RDWR | O_CREAT | O_EXCL, 0600);
-#endif
     if (fid < 0) {
        ErrorLog(0, rstTapeInfoPtr->taskId, errno, 0,
                 "Can't open temporary text file: %s\n", filename);