<para>The behaviour of <computeroutput>realloc()</computeroutput> is
implementation defined (in C17, in C23 it is likely to become
undefined). Valgrind tries to work in the same way as the
- underlying OS and C runtime library. However, if you use a
- different C runtime library then this default may be wrong.
- For instance, if you use Valgrind on Linux installed via a package
- and use the musl C runtime or the JEMalloc library then
- consider using
+ underlying system and C runtime library that it was configured and built on.
+ However, if you use a different C runtime library then this default may be wrong.
+ If the value is <option>yes</option> then <varname>realloc</varname> will
+ deallocate the memory and return NULL. If the value is <option>no</option> then
+ <varname>realloc</varname> will not deallocate the memory and
+ the size will be handled as though it were one byte.</para>
+ <para>As an example, if you use Valgrind installed via a package on a
+ Linux distro using GNU libc but link your test executable with musl libc or
+ the JEMalloc library then consider using
<computeroutput>--realloc-zero-bytes-frees=no</computeroutput>.
</para>
<para>Address Sanitizer has a similar and even wordier option
startup and makes it use more memory (typically for each inlined
piece of code, 6 words and space for the function name), but it
results in more descriptive stacktraces. Currently,
- this functionality is enabled by default only for Linux,
+ this functionality is enabled by default only for Linux, FreeBSD,
Android and Solaris targets and only for the tools Memcheck, Massif,
Helgrind and DRD. Here is an example of some stacktraces with
<option>--read-inline-info=no</option>:
<option><![CDATA[--run-libc-freeres=<yes|no> [default: yes] ]]></option>
</term>
<listitem>
- <para>This option is only relevant when running Valgrind on Linux.</para>
+ <para>This option is only relevant when running Valgrind on Linux with
+ GNU libc.</para>
<para>The GNU C library (<function>libc.so</function>), which is
used by all programs, may allocate memory for its own uses.
<option><![CDATA[--run-cxx-freeres=<yes|no> [default: yes] ]]></option>
</term>
<listitem>
- <para>This option is only relevant when running Valgrind on Linux
- or Solaris C++ programs.</para>
+ <para>This option is only relevant when running Valgrind on Linux,
+ FreeBSD or Solaris C++ programs using libstdc++.</para>
<para>The GNU Standard C++ library (<function>libstdc++.so</function>),
which is used by all C++ programs compiled with g++, may allocate memory
any shared library having no soname. </para>
</listitem>
- <listitem>
- <para>To run a "default" Firefox build for Linux, in which
- JEMalloc is linked in to the main executable,
- use <option>--soname-synonyms=somalloc=NONE</option>.
- </para>
- </listitem>
-
<listitem>
<para>To only intercept allocation symbols in the default
system libraries, but not in any other shared library or the
</listitem>
</varlistentry>
+ <varlistentry id="opt.show-realloc-size-zero"
+ xreflabel="--show-realloc-size-zero">
+ <term>
+ <option><![CDATA[--show-realloc-size-zero=<yes|no> [default: yes] ]]></option>
+ </term>
+ <listitem>
+ <para>When enabled, Memcheck checks for uses of <varname>realloc</varname> with a size of zero.
+ This usage of <varname>realloc</varname> is unsafe since it is not portable. On some systems it
+ will behave like <varname>free</varname>. On other systems it will either do nothing or else
+ behave like a call to <varname>free</varname> followed by a call to <varname>malloc</varname>
+ with a size of zero.</para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="opt.ignore-ranges" xreflabel="--ignore-ranges">
<term>
<option><![CDATA[--ignore-ranges=0xPP-0xQQ[,0xRR-0xSS] ]]></option>