]> The Tcpdump Group git mirrors - libpcap/commitdiff
Plug memory leak.
authorGuy Harris <[email protected]>
Thu, 14 Feb 2019 21:16:02 +0000 (13:16 -0800)
committerGuy Harris <[email protected]>
Thu, 14 Feb 2019 21:16:02 +0000 (13:16 -0800)
If the URL had "file" as the scheme, *and* if we couldn't allocate
memory for the path, we'd leak the memory we allocated for the scheme.

Should address Coverity CID 1442632 (although Coverity misdiagnosed the
underlying problem).

pcap.c

diff --git a/pcap.c b/pcap.c
index c134cd6029b63502227e0f42f3f5e655756b8007..7336260481206fe53a4df3473eab795258c75a5d 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -1663,13 +1663,14 @@ pcap_parse_source(const char *source, char **schemep, char **userinfop,
         * the pathname.
         */
        if (pcap_strcasecmp(scheme, "file") == 0) {
-               *schemep = scheme;
                *pathp = strdup(colonp + 3);
                if (*pathp == NULL) {
                        pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
                            errno, "malloc");
+                       free(scheme);
                        return (-1);
                }
+               *schemep = scheme;
                return (0);
        }