Bug 13670

Summary: Resource leaks in objstrip.c
Product: Platform Specific/Hardware Reporter: Martin Ettl (ettl.martin)
Component: AlphaAssignee: Richard Henderson (rth)
Status: RESOLVED INVALID    
Severity: normal CC: alan
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.30 Subsystem:
Regression: No Bisected commit-id:

Description Martin Ettl 2009-06-29 07:56:45 UTC
Hello,

i have checked the source of the linux kernel with a static code analyis tool (cppcheck). It found two resource leaks in file  "linux-2.6.30/arch/alpha/boot/tools/objstrip.c".

cppcheck prints the following output:

[linux-2.6.30/arch/alpha/boot/tools/objstrip.c:134]: (error) Resource leak: fd
[linux-2.6.30/arch/alpha/boot/tools/objstrip.c:134]: (error) Resource leak: ofd


Take a look at file objstrip.c at line 134:


...
	printf("%lu\n", size);
	return 0;
...

Indeed fd and ofd are not closed.
A possible fix might be:
...
	printf("%lu\n", size);
        close(fd);
        close(ofd);
	return 0;
...


Best regards

Ettl Martin
Comment 1 Alan 2009-06-29 11:01:54 UTC
File handles are closed on exit and this is main() returning  - buggy tools methinks