Skip to contentSkip to conversation

found another resource leak in file xdiff-interface.c

DISCUSSION Martin Ettl 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi friends,

i have detected another resource leak (using the static code analysis tool cppcheck) in file xdiff-interface.c.

The tool prints the following warning:

[git.1.6.3.3/xdiff-interface.c:215](error) resource leak f

int read_mmfile(mmfile_t *ptr, const char *filename) {
//...

	if (sz && fread(ptr->ptr, sz, 1, f) != 1)
		return error("Could not read %s", filename);
	fclose(f);
// ....
	ptr->size = sz;
	return 0;
}

A possible solution might be:

int read_mmfile(mmfile_t *ptr, const char *filename) {
//...

	if (sz && fread(ptr->ptr, sz, 1, f) != 1)
        {
	        fclose(f);
		return error("Could not read %s", filename);
        }
	fclose(f);
// ....
	ptr->size = sz;
	return 0;
}

Best regards

Ettl Martin

Signature · 2 lines
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01