Fix memory bugs.
[fprobe-ulog.git] / src / fprobe-ulog.c
index ae855bd..e939dab 100644 (file)
@@ -831,7 +831,10 @@ void *emit_thread()
                        gettimeofday(&now, 0);
                        timeout.tv_sec = now.tv_sec + emit_timeout;
                        /* Do not wait until emit_packet will filled - it may be too long */
-                       if (pthread_cond_timedwait(&emit_cond, &emit_mutex, &timeout) && emit_count) {
+            int res=-1;
+            while ((res=pthread_cond_timedwait(&emit_cond, &emit_mutex, &timeout))==-1) continue;
+
+                       if (res && emit_count) {
                 //my_log(LOG_INFO,"Timeout: %d, %d",emit_count, timeout.tv_sec);
                                pthread_mutex_unlock(&emit_mutex);
                                goto sendit;
@@ -964,7 +967,8 @@ void *unpending_thread()
                while (!(pending_tail->flags & FLOW_PENDING)) {
                        gettimeofday(&now, 0);
                        timeout.tv_sec = now.tv_sec + unpending_timeout;
-                       pthread_cond_timedwait(&unpending_cond, &unpending_mutex, &timeout);
+                       while (pthread_cond_timedwait(&unpending_cond, &unpending_mutex, &timeout)==-1)
+                continue;
                }
 
 #if ((DEBUG) & (DEBUG_S | DEBUG_U))
@@ -1010,7 +1014,8 @@ void *scan_thread()
        for (;;) {
                gettime(&now);
                timeout.tv_sec = now.sec + scan_interval;
-               pthread_cond_timedwait(&scan_cond, &scan_mutex, &timeout);
+               while (pthread_cond_timedwait(&scan_cond, &scan_mutex, &timeout)==-1)
+            continue;
 
                gettime(&now);
 #if ((DEBUG) & DEBUG_S)
@@ -1500,7 +1505,7 @@ bad_lhost:
        /* Process collectors parameters. Brrrr... :-[ */
 
        npeers = argc - optind;
-       if (npeers > 1) {
+       if (npeers >= 1) {
                /* Send to remote Netflow collector */
                if (!(peers = malloc(npeers * sizeof(struct peer)))) goto err_malloc;
                for (i = optind, npeers = 0; i < argc; i++, npeers++) {
@@ -1565,10 +1570,8 @@ bad_collector:
        }
        else if (parms[fflag].count) {
                // log into a file
-               if (!(peers = malloc(npeers * sizeof(struct peer)))) goto err_malloc;
-               if (!(peers[npeers].fname = malloc(strnlen(parms[fflag].arg,MAX_PATH_LEN)))) goto err_malloc;
-               strncpy(peers[npeers].fname, parms[fflag].arg, MAX_PATH_LEN);
-
+               if (!(peers = malloc(sizeof(struct peer)))) goto err_malloc;
+               if (!(peers[npeers].fname = strndup(parms[fflag].arg, MAX_PATH_LEN))) goto err_malloc;
                peers[npeers].write_fd = START_DATA_FD;
                peers[npeers].type = PEER_FILE;
                peers[npeers].seq = 0;