[LTP] memcg/memcontrol02: fix fd leak in cleanup path

Disha Goel disgoel@linux.ibm.com
Tue Aug 18 14:21:20 CEST 2026


On 10/08/26 3:11 pm, Andrea Cervesato wrote:
> Hi Disha,
> 
>>> fd is initialized to 0 (a valid file descriptor) so the cleanup()
>>> guard 'if (fd > -1)' would never trigger.
>>
>> Could this explanation be corrected? Zero is greater than -1, and the
>> cleanup guard is added by this patch rather than being an existing guard.
>> The relevant problem is that -1 is needed to distinguish an unopened
>> descriptor before cleanup tries to close it.
>>
>>> +	if (fd > -1)
>>> +		SAFE_CLOSE(fd);
>>
>> Could this use `fd != -1` instead? LTP file descriptors use -1 as the
>> invalid sentinel, and the LTP convention requires this form for cleanup
>> guards.
> 
> this is correct.
> 
>>
>> --- [PATCH 2/2] ---
>>
>>> #include <inttypes.h>
>>>
>>> -		tst_res(TINFO, "Child %d in %s: Allocating anon: %"PRIdPTR,
>>> +		tst_res(TINFO, "Child %d in %s: Allocating anon: %zu",
>>
>> Could the now-unused `<inttypes.h>` include be removed from both
>> memcontrol03.c and memcontrol04.c? This patch replaces every `PRIdPTR`
>> use in both files.
> 
> And also this is correct. We should split the patch in two: one for
> memcontrol03 and one for memcontrol04
> 
Hi Andrea,

Thanks for the review. I've addressed all the comments and sent a v2.

Link to v2: 
https://lore.kernel.org/ltp/20260818121436.1397-1-disgoel@linux.ibm.com/

> --
> Andrea Cervesato
> SUSE QE Automation Engineer Linux
> andrea.cervesato@suse.com

-- 
Regards,
Disha



More information about the ltp mailing list