MallocLogFile ignored by /bin/ls and others

Originator:Per.Mildner.usenet
Number:rdar://28691464 Date Originated:10-Oct-2016
Status:Open Resolved:
Product:macOS Product Version:10.12
Classification: Reproducible:Always
 
Summary:
/bin/ls and many other builtins do not obey the MallocLogFile
environment variabl , and instead unconditionally write some
information to stderr if any of the malloc debug environment variables
are set, e.g. MallocScribble.

This bug is new in 10.12, it was not present in 10.11 and earlier.

This problem does not seem to happen for user written executables,
i.e. in that case all malloc debug output goes into the file specified
iwth MallocLogFile.

This bug makes it impractical to globally enable the malloc debug
flags during build/test of our application. The only short term
workaround is to stop using malloc debug flags, which is unfortunate.


Transcript demonstrating that the problem happens with /bin/ls, and
does not happen with my own code (m.c).

bash-3.2$ /bin/ls
m.c

# The following should not write "... enabling ..." to stderr, it
# should go into ls_malloc.log
bash-3.2$ MallocScribble=yes MallocLogFile=$PWD/ls_malloc.log /bin/ls
ls(666,0x7fffeb0a03c0) malloc: enabling scribbling to detect mods to free blocks
m.c

# This shows that no ls_malloc.log was created
bash-3.2$ /bin/ls
m.c

bash-3.2$ cc m.c -Wall -Werror -o m

# This shows that the "... enabling ..." is not written to stderr,
# i.e. MallocLogFile works as it should.
bash-3.2$ MallocScribble=yes MallocLogFile=$PWD/m_malloc.log ./m
Abort trap: 6

# This shows that the m_malloc.log file was created, and has both the
# "... enabling ..." info, and the double-free error
# report. I.e. everything works as it should. 
bash-3.2$ /bin/ls
m		m.c		m_malloc.log
bash-3.2$ cat m_malloc.log 
m(671,0x7fffeb0a03c0) malloc: enabling scribbling to detect mods to free blocks
m(671,0x7fffeb0a03c0) malloc: *** error for object 0x7fc159400350: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

bash-3.2$ cat m.c
#include <stdlib.h>
int main(int argc, char **argv)
{
  (void)argc; (void)argv;
  void *p = malloc(10);
  free(p);
  free(p); /* double free */
  return 0;
}
bash-3.2$ uname -a
Darwin XXX 16.0.0 Darwin Kernel Version 16.0.0: Mon Aug 29 17:56:20 PDT 2016; root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64
bash-3.2$ sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.12
BuildVersion:	16A323
bash-3.2$

Steps to Reproduce:
1. MallocScribble=yes MallocLogFile=$PWD/ls_malloc.log /bin/ls

Expected Results:
No output should be output on stderr.

Actual Results:
Information from the malloc debug code is output to stderr.

Version:
ProductName:	Mac OS X
ProductVersion:	10.12
BuildVersion:	16A323

Notes:


Configuration:


Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!