~sircmpwn/ctools

86dbeab2924c575f008b010a87571604618eff30 — Stefan Tatschner 1 year, 21 days ago 291b64b
chown/chgrp: Fix memory leak

$ meson test -C build --verbose chown
ninja: Entering directory `/home/rumpelsepp/Projects/vendor/ctools/build'
ninja: no work to do.
should_handle_simple          OK
should_handle_several         OK
should_handle_mutex_options   OK
should_handle_recursive
=================================================================
==65006==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 65632 byte(s) in 2 object(s) allocated from:
    #0 0x7f2a9b3f9ada in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f2a9a88160a in __alloc_dir (/usr/lib/libc.so.6+0xc460a)

SUMMARY: AddressSanitizer: 65632 byte(s) leaked in 2 allocation(s).
FAIL
should_handle_recursive_Hflag
=================================================================
==65054==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 65632 byte(s) in 2 object(s) allocated from:
    #0 0x7f4cd631fada in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f4cd57a760a in __alloc_dir (/usr/lib/libc.so.6+0xc460a)

SUMMARY: AddressSanitizer: 65632 byte(s) leaked in 2 allocation(s).
FAIL
should_handle_recursive_Lflag
=================================================================
==65102==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 131264 byte(s) in 4 object(s) allocated from:
    #0 0x7f7dd8029ada in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f7dd74b160a in __alloc_dir (/usr/lib/libc.so.6+0xc460a)

SUMMARY: AddressSanitizer: 131264 byte(s) leaked in 4 allocation(s).
FAIL
should_handle_recursive_Pflag
=================================================================
==65150==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32816 byte(s) in 1 object(s) allocated from:
    #0 0x7f7914ad4ada in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f7913f5c60a in __alloc_dir (/usr/lib/libc.so.6+0xc460a)

SUMMARY: AddressSanitizer: 32816 byte(s) leaked in 1 allocation(s).
FAIL
should_handle_owner_change    SKIP($ESCALATE undefined)
OK
Passed: 4 tests
Failed: 4 tests
1/1 chown                                   FAIL     0.92 s (exit status 1)
1 files changed, 15 insertions(+), 4 deletions(-)

M src/chgrp.c
M src/chgrp.c => src/chgrp.c +15 -4
@@ 105,8 105,11 @@ process(const char *path, struct context *ctx, int depth)
		perror(path);
		return 1;
	}

	DIR *dir = NULL;
	int r = 0;
	if (recurse) {
		DIR *dir = opendir(path);
		dir = opendir(path);
		if (!dir) {
			perror(path);
			return 1;


@@ 125,15 128,23 @@ process(const char *path, struct context *ctx, int depth)
			strcat(subpath, "/");
			strcat(subpath, dirent->d_name);
			if (process(subpath, ctx, depth + 1) != 0) {
				return 1;
				r = -1;
				goto out;
			}
		}
		if (errno != 0) {
			perror(path);
			return 1;
			r = -1;
			goto out;
		}
	}
	return 0;

out:
	if (dir != NULL) {
		closedir(dir);
	}

	return r;
}

int