]> git.sesse.net Git - nageru/commitdiff
Fix some addrinfo leaks in the error paths for outbound SRT, by means of RAII.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 17 Sep 2023 14:59:19 +0000 (16:59 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 17 Sep 2023 14:59:19 +0000 (16:59 +0200)
nageru/video_encoder.cpp

index ec96acc58d9c82e24bbb33338bb0dccdb4c2de43..c1938d505d5e666662e027cd62608b1bc628f376 100644 (file)
@@ -376,6 +376,8 @@ int VideoEncoder::connect_to_srt()
                return -1;
        }
 
+       unique_ptr<addrinfo, decltype(freeaddrinfo) *> ai_cleanup(ai, &freeaddrinfo);
+
        for (const addrinfo *cur = ai; cur != nullptr; cur = cur->ai_next) {
                // Seemingly, srt_create_socket() isn't universal; once we try to connect,
                // it gets locked to either IPv4 or IPv6. So we need to create a new one
@@ -392,12 +394,10 @@ int VideoEncoder::connect_to_srt()
                        continue;
                }
                fprintf(stderr, "Connected to destination SRT endpoint at %s.\n", print_addrinfo(cur).c_str());
-               freeaddrinfo(ai);
                return sock;
        }
 
        // Out of candidates, so give up.
-       freeaddrinfo(ai);
        return -1;
 }