Package: coreutils
Version: 8.30-3+b1
Severity: normal

Dear Maintainer,

IF_LINT is defined to nothing, so free is never called.

$ apt source coreutils

In file coreutils-8.30/src/system.h I see:
-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--
/* Use this to suppress gcc's '...may be used before initialized' warnings. */
#ifdef lint
# define IF_LINT(Code) Code
#else
# define IF_LINT(Code) /* empty */
#endif
-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--

For example in seq.c file I see:
$ grep IF_LINT coreutils-8.30/src/seq.c
      IF_LINT (free (buf));
          IF_LINT (free (s1));
          IF_LINT (free (s2));


If I runt seq with valgrind I get the following lost memory block:
# apt install coreutils-dbgsym

$ valgrind --leak-check=yes --leak-check=full --show-leak-kinds=all seq 10
==103500== Memcheck, a memory error detector
==103500== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==103500== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==103500== Command: seq 10
==103500==
1
2
3
4
5
6
7
8
9
10
==103500==
==103500== HEAP SUMMARY:
==103500==     in use at exit: 8,192 bytes in 1 blocks
==103500==   total heap usage: 34 allocs, 33 frees, 13,331 bytes allocated
==103500==
==103500== 8,192 bytes in 1 blocks are definitely lost in loss record 1 of 1
==103500== at 0x483877F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==103500==    by 0x10E178: xmalloc (xmalloc.c:41)
==103500==    by 0x10B336: seq_fast (seq.c:485)
==103500==    by 0x10AB7D: main (seq.c:647)
==103500==
==103500== LEAK SUMMARY:
==103500==    definitely lost: 8,192 bytes in 1 blocks
==103500==    indirectly lost: 0 bytes in 0 blocks
==103500==      possibly lost: 0 bytes in 0 blocks
==103500==    still reachable: 0 bytes in 0 blocks
==103500==         suppressed: 0 bytes in 0 blocks
==103500==
==103500== For lists of detected and suppressed errors, rerun with: -s
==103500== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)


If add the following line of code, recompile and execute again:
$ sed '533 i if( buf ) {free(buf);}' coreutils-8.30/src/seq.c > coreutils-8.30/src/seq1.c
$ mv coreutils-8.30/src/seq.c coreutils-8.30/src/seq.c.bak
$ mv coreutils-8.30/src/seq1.c coreutils-8.30/src/seq.c
# apt build-dep coreutils
$ ./debian/rules build

$ valgrind --leak-check=yes --leak-check=full --show-leak-kinds=all ./coreutils-8.30/src/seq 10
==122470== Memcheck, a memory error detector
==122470== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==122470== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==122470== Command: /tmp/2/coreutils-8.30/src/seq 10
==122470==
1
2
3
4
5
6
7
8
9
10
==122470==
==122470== HEAP SUMMARY:
==122470==     in use at exit: 0 bytes in 0 blocks
==122470==   total heap usage: 34 allocs, 34 frees, 13,331 bytes allocated
==122470==
==122470== All heap blocks were freed -- no leaks are possible
==122470==
==122470== For lists of detected and suppressed errors, rerun with: -s
==122470== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


The error is gone.


I try the following: restore the original seq.c file, define IF_LINT in seq.c, rebuild and execute again
$ cp coreutils-8.30/src/seq.c.bak coreutils-8.30/src/seq.c
$ sed '44 i #define IF_LINT(Code) Code' coreutils-8.30/src/seq.c > coreutils-8.30/src/seq1.c
$ mv coreutils-8.30/src/seq1.c coreutils-8.30/src/seq.c
$ ./debian/rules clean
$ ./debian/rules build

$ valgrind --leak-check=yes --leak-check=full --show-leak-kinds=all coreutils-8.30/src/seq 10
==141237== Memcheck, a memory error detector
==141237== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==141237== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==141237== Command: /tmp/2/coreutils-8.30/src/seq 10
==141237==
1
2
3
4
5
6
7
8
9
10
==141237==
==141237== HEAP SUMMARY:
==141237==     in use at exit: 0 bytes in 0 blocks
==141237==   total heap usage: 34 allocs, 34 frees, 13,331 bytes allocated
==141237==
==141237== All heap blocks were freed -- no leaks are possible
==141237==
==141237== For lists of detected and suppressed errors, rerun with: -s
==141237== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


Please define correctly IF_LINT, note that the #define is in more than one file (I execute a simple search):
getndelim2.c
inet_ntop.c
trim.c
vasnprintf.c
system.h

Ciao
Davide


-- System Information:
Debian Release: bullseye/sid
  APT prefers testing-debug
  APT policy: (500, 'testing-debug'), (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 5.7.17-dp-20200831 (SMP w/4 CPU threads; PREEMPT)
Kernel taint flags: TAINT_UNSIGNED_MODULE
Locale: LANG=it_IT.utf8, LC_CTYPE=it_IT.utf8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages coreutils depends on:
ii  libacl1      2.2.53-8
ii  libattr1     1:2.4.48-5
ii  libc6        2.31-3
ii  libselinux1  3.1-2

coreutils recommends no packages.

coreutils suggests no packages.

-- debconf-show failed

Reply via email to