]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
scan-build: fix resource leaks on error paths
authorAndrew Tridgell <andrew@tridgell.net>
Fri, 12 Jun 2026 00:53:10 +0000 (10:53 +1000)
committerAndrew Tridgell <andrew@tridgell.net>
Mon, 15 Jun 2026 22:55:39 +0000 (08:55 +1000)
clientserver.c: close the --early-input-file FILE* on the
fstat/oversize/early-EOF error returns; it was only closed on the
success path.
getgroups.c: free the gid list before returning.

clientserver.c
getgroups.c

index cc59663ad3aec048fc0a18dcc56b275046fd0f9b..dbde116ca5a5c3ba57566b840f888d3d6e21d24e 100644 (file)
@@ -270,11 +270,14 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char
                FILE *f = fopen(early_input_file, "rb");
                if (!f || do_fstat(fileno(f), &st) < 0) {
                        rsyserr(FERROR, errno, "failed to open %s", early_input_file);
+                       if (f)
+                               fclose(f);
                        return -1;
                }
                early_input_len = st.st_size;
                if (early_input_len > (int)sizeof line) {
                        rprintf(FERROR, "%s is > %d bytes.\n", early_input_file, (int)sizeof line);
+                       fclose(f);
                        return -1;
                }
                if (early_input_len > 0) {
@@ -283,6 +286,7 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char
                                int len;
                                if (feof(f)) {
                                        rprintf(FERROR, "Early EOF in %s\n", early_input_file);
+                                       fclose(f);
                                        return -1;
                                }
                                len = fread(line, 1, early_input_len, f);
index 8a37ed0b7a20c2d6e988b3d0eb838dbb36d42f03..6b83d452bd2369df981423f7997fed4f1761d350 100644 (file)
@@ -57,5 +57,6 @@
                printf("%lu", (unsigned long)gid);
        printf("\n");
 
+       free(list);
        return 0;
 }