From: Steinar H. Gunderson Date: Sun, 17 Sep 2023 14:59:19 +0000 (+0200) Subject: Fix some addrinfo leaks in the error paths for outbound SRT, by means of RAII. X-Git-Tag: 2.3.0~14 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=448bfb337a97e9352b8d912749fcf0989e0eef25 Fix some addrinfo leaks in the error paths for outbound SRT, by means of RAII. --- diff --git a/nageru/video_encoder.cpp b/nageru/video_encoder.cpp index ec96acc..c1938d5 100644 --- a/nageru/video_encoder.cpp +++ b/nageru/video_encoder.cpp @@ -376,6 +376,8 @@ int VideoEncoder::connect_to_srt() return -1; } + unique_ptr 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; }