]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
log/pcap: work around scan-build fp
authorVictor Julien <vjulien@oisf.net>
Tue, 25 Apr 2023 05:23:17 +0000 (07:23 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 25 Apr 2023 05:23:20 +0000 (07:23 +0200)
log-pcap.c:1008:24: warning: Use of memory after it is freed [unix.Malloc]
            if (remove(pf->filename) != 0) {
                       ^~~~~~~~~~~~
1 warning generated.

src/log-pcap.c

index 670977404213d0e1aabee6ccd997bc8fe8f4a3d2..083d840cbd43cda56c8ecd15154a22e99e89fa4b 100644 (file)
@@ -1004,14 +1004,16 @@ static TmEcode PcapLogInitRingBuffer(PcapLogData *pl)
     if (pl->file_cnt > pl->max_files) {
         PcapFileName *pf = TAILQ_FIRST(&pl->pcap_file_list);
         while (pf != NULL && pl->file_cnt > pl->max_files) {
+            TAILQ_REMOVE(&pl->pcap_file_list, pf, next);
+
             SCLogDebug("Removing PCAP file %s", pf->filename);
             if (remove(pf->filename) != 0) {
                 SCLogWarning("Failed to remove PCAP file %s: %s", pf->filename, strerror(errno));
             }
-            TAILQ_REMOVE(&pl->pcap_file_list, pf, next);
             PcapFileNameFree(pf);
-            pf = TAILQ_FIRST(&pl->pcap_file_list);
             pl->file_cnt--;
+
+            pf = TAILQ_FIRST(&pl->pcap_file_list);
         }
     }