afsmonitor: avoid double free on exit
[openafs.git] / src / afsmonitor / afsmonitor.c
index e7b3030..1f28e3d 100644 (file)
@@ -56,7 +56,6 @@ int afsmon_debug = 0;         /* debug info to file ? */
 FILE *debugFD;                 /* debugging file descriptor */
 static int afsmon_output = 0;  /* output to file ? */
 static int afsmon_detOutput = 0;       /* detailed output ? */
-static int afsmon_onceOnly = 0;        /* probe once only ? (not implemented) */
 int afsmon_probefreq;          /* probe frequency */
 static int wpkg_to_use;                /* graphics package to use */
 static char output_filename[80];       /* output filename */
@@ -455,8 +454,8 @@ afsmon_Exit(int a_exitVal)  /* exit code */
                        /* free xstat_cm_Results data */
                        free(tmp_xstat_cmPR->data.AFSCB_CollData_val);
                        free(tmp_xstat_cmPR->connP);
+                       free(tmp_xstat_cmPR);
                    }
-                   free(tmp_cmlist->cmResults);
 
                    /* free the cm list item */
                    free(tmp_cmlist);
@@ -3724,7 +3723,6 @@ afsmon_execute(void)
     int FSinitFlags = 0;       /* flags for xstat_fs_Init */
     int CMinitFlags = 0;       /* flags for xstat_cm_Init */
     int code;                  /* function return code */
-    struct timeval tv;         /* time structure */
     int i;
     short index;
 
@@ -3794,8 +3792,6 @@ afsmon_execute(void)
        }
 
        FSinitFlags = 0;
-       if (afsmon_onceOnly)    /* option not provided at this time */
-           FSinitFlags |= XSTAT_FS_INITFLAG_ONE_SHOT;
 
        if (afsmon_debug) {
            fprintf(debugFD, "[ %s ] Calling xstat_fs_Init \n", rn);
@@ -3867,8 +3863,6 @@ afsmon_execute(void)
        collIDs[num_cm_collections++] = AFSCB_XSTATSCOLL_FULL_PERF_INFO;
 
        CMinitFlags = 0;
-       if (afsmon_onceOnly)    /* once only ? */
-           CMinitFlags |= XSTAT_CM_INITFLAG_ONE_SHOT;
 
        if (afsmon_debug) {
            fprintf(debugFD, "[ %s ] Calling xstat_cm_Init \n", rn);
@@ -3892,19 +3886,6 @@ afsmon_execute(void)
 
 
     /* end of process cache manager entries */
-    /* if only one probe was required setup a waiting process for the
-     * termination signal */
-    if (afsmon_onceOnly) {
-       code = LWP_WaitProcess(&terminationEvent);
-       if (code) {
-           if (afsmon_debug) {
-               fprintf(debugFD, "LWP_WaitProcess() returned error %d\n",
-                       code);
-               fflush(debugFD);
-           }
-           afsmon_Exit(135);
-       }
-    }
 
     /* start the gtx input server */
     code = (intptr_t)gtx_InputServer(afsmon_win);
@@ -3915,24 +3896,8 @@ afsmon_execute(void)
 
     /* This part of the code is reached only if the input server is not started
      * for debugging purposes */
-
-    /* sleep forever */
-    tv.tv_sec = 24 * 60;
-    tv.tv_usec = 0;
-    fprintf(stderr, "[ %s ] going to sleep ...\n", rn);
-    while (1) {
-       code = IOMGR_Select(0,  /*Num fds */
-                           0,  /*Descriptors ready for reading */
-                           0,  /*Descriptors ready for writing */
-                           0,  /*Descriptors with exceptional conditions */
-                           &tv);       /*Timeout structure */
-       if (code) {
-           fprintf(stderr,
-                   "[ %s ] IOMGR_Select() returned non-zero value %d\n", rn,
-                   code);
-           afsmon_Exit(145);
-       }
-    }                          /* while sleep */
+    xstat_cm_Wait(0); /* sleep forever */
+    return 0;
 }