|
[Valgrind-developers] valgrind3.13.0 is not calling application
defined global new/delete operators.
From: Michael M. <mos...@gm...> - 2017-11-09 09:27:33
|
Hi,
I have a short program that overrides global new and delete operators. When
running it in valgrind 3.13.0 then the global new/delete operators of the
application are not called, in valgrind 3.10.1 the global new/delete
operators are called. My questions are: why this behavior in valgrind
3.13.0 ? how can we get valgrind3.13.0 to call the global new/delete of
the application, is there a configuration setting/command line switch that
enables this? (environment OS Linux, Ubuntu 14.04.5 LTS, x86_64)
The program.
#include <malloc.h>
#include <new>
void* operator new (size_t size_i) throw (std::bad_alloc)
{
fprintf(stderr,"new %d (operator new (size_t size_i) throw
(std::bad_alloc))\n", __LINE__);
return malloc(size_i);
}
void* operator new (size_t size_i, const std::nothrow_t& nothrow_value)
throw()
{
fprintf(stderr,"new %d (operator new (size_t size_i, const
std::nothrow_t& nothrow_value) throw())\n", __LINE__);
return malloc(size_i);
}
void* operator new[] (size_t size_i) throw (std::bad_alloc)
{
fprintf(stderr,"new %d (operator new[] (size_t size_i) throw
(std::bad_alloc)) \n", __LINE__);
return malloc(size_i);
}
void* operator new[] (size_t size_i, const std::nothrow_t&
nothrow_value) throw()
{
fprintf(stderr,"new %d (operator new[] (size_t size_i, const
std::nothrow_t& nothrow_value) throw()) \n", __LINE__);
return malloc(size_i);
}
void operator delete (void* p_i) throw()
{
fprintf(stderr, "delete %d (operator delete (void* p_i)
throw())\n",__LINE__);
free(p_i);
}
void operator delete (void* p_i, const std::nothrow_t&
nothrow_constant) throw()
{
fprintf(stderr, "delete %d\n",__LINE__);
free(p_i);
}
void operator delete[] (void* p_i) throw()
{
fprintf(stderr, "delete %d\n",__LINE__);
free(p_i);
}
void operator delete[] (void* p_i, const std::nothrow_t&
nothrow_constant) throw()
{
fprintf(stderr, "delete %d\n",__LINE__);
free(p_i);
}
#include <stdio.h>
main()
{
fprintf(stderr, "ku !\n");
char * a = new char[123];
delete [] a;
int * b = new int();
delete b;
return 0;
}
Now compile it
gcc -g valg.cpp -lstdc++
run it without valgrind
$ ./a.out
ku !
new 19 (operator new[] (size_t size_i) throw (std::bad_alloc))
delete 43
new 6 (operator new (size_t size_i) throw (std::bad_alloc))
delete 31 (operator delete (void* p_i) throw())
With valgrind 3.13.0 global operator new is not called.
valgrind ./a.out
==24181== Memcheck, a memory error detector
==24181== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et
al.
==24181== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright
info
==24181== Command: ./a.out
==24181==
ku !
==24181==
with valgrind 3.10.1
valgrind ./a.out
==32055== Memcheck, a memory error detector
==32055== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==32055== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==32055== Command: ./a.out
==32055==
ku !
new 19 (operator new[] (size_t size_i) throw (std::bad_alloc))
delete 43
new 6 (operator new (size_t size_i) throw (std::bad_alloc))
delete 31 (operator delete (void* p_i) throw())
==32055==
==32055== HEAP SUMMARY:
==32055== in use at exit: 0 bytes in 0 blocks
==32055== total heap usage: 2 allocs, 2 frees, 127 bytes allocated
==32055==
==32055== All heap blocks were freed -- no leaks are possible
==32055==
==32055== For counts of detected and suppressed errors, rerun with: -v
==32055== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
|
|
From: Schmidt, A. <adr...@si...> - 2017-11-09 10:05:33
|
Valgrind’s behavior regarding wrapping new/delete changed in version 3.12.0.
From the changelog:
* Replacement/wrapping of malloc/new related functions is now done not just
for system libraries by default, but for any globally defined malloc/new
related function (both in shared libraries and statically linked alternative
malloc implementations). The dynamic (runtime) linker is excluded, though.
To only intercept malloc/new related functions in
system libraries use --soname-synonyms=somalloc=nouserintercepts (where
"nouserintercepts" can be any non-existing library name).
This new functionality is not implemented for MacOS X.
HTH,
Adriaan
From: Michael Moser [mailto:mos...@gm...]
Sent: Donnerstag, 9. November 2017 10:27
To: Val...@li...
Subject: [Valgrind-developers] valgrind3.13.0 is not calling application defined global new/delete operators.
Hi,
I have a short program that overrides global new and delete operators. When running it in valgrind 3.13.0 then the global new/delete operators of the application are not called, in valgrind 3.10.1 the global new/delete operators are called. My questions are: why this behavior in valgrind 3.13.0 ? how can we get valgrind3.13.0 to call the global new/delete of the application, is there a configuration setting/command line switch that enables this? (environment OS Linux, Ubuntu 14.04.5 LTS, x86_64)
The program.
#include <malloc.h>
#include <new>
void* operator new (size_t size_i) throw (std::bad_alloc)
{
fprintf(stderr,"new %d (operator new (size_t size_i) throw (std::bad_alloc))\n", __LINE__);
return malloc(size_i);
}
void* operator new (size_t size_i, const std::nothrow_t& nothrow_value) throw()
{
fprintf(stderr,"new %d (operator new (size_t size_i, const std::nothrow_t& nothrow_value) throw())\n", __LINE__);
return malloc(size_i);
}
void* operator new[] (size_t size_i) throw (std::bad_alloc)
{
fprintf(stderr,"new %d (operator new[] (size_t size_i) throw (std::bad_alloc)) \n", __LINE__);
return malloc(size_i);
}
void* operator new[] (size_t size_i, const std::nothrow_t& nothrow_value) throw()
{
fprintf(stderr,"new %d (operator new[] (size_t size_i, const std::nothrow_t& nothrow_value) throw()) \n", __LINE__);
return malloc(size_i);
}
void operator delete (void* p_i) throw()
{
fprintf(stderr, "delete %d (operator delete (void* p_i) throw())\n",__LINE__);
free(p_i);
}
void operator delete (void* p_i, const std::nothrow_t& nothrow_constant) throw()
{
fprintf(stderr, "delete %d\n",__LINE__);
free(p_i);
}
void operator delete[] (void* p_i) throw()
{
fprintf(stderr, "delete %d\n",__LINE__);
free(p_i);
}
void operator delete[] (void* p_i, const std::nothrow_t& nothrow_constant) throw()
{
fprintf(stderr, "delete %d\n",__LINE__);
free(p_i);
}
#include <stdio.h>
main()
{
fprintf(stderr, "ku !\n");
char * a = new char[123];
delete [] a;
int * b = new int();
delete b;
return 0;
}
Now compile it
gcc -g valg.cpp -lstdc++
run it without valgrind
$ ./a.out
ku !
new 19 (operator new[] (size_t size_i) throw (std::bad_alloc))
delete 43
new 6 (operator new (size_t size_i) throw (std::bad_alloc))
delete 31 (operator delete (void* p_i) throw())
With valgrind 3.13.0 global operator new is not called.
valgrind ./a.out
==24181== Memcheck, a memory error detector
==24181== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==24181== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==24181== Command: ./a.out
==24181==
ku !
==24181==
with valgrind 3.10.1
valgrind ./a.out
==32055== Memcheck, a memory error detector
==32055== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==32055== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==32055== Command: ./a.out
==32055==
ku !
new 19 (operator new[] (size_t size_i) throw (std::bad_alloc))
delete 43
new 6 (operator new (size_t size_i) throw (std::bad_alloc))
delete 31 (operator delete (void* p_i) throw())
==32055==
==32055== HEAP SUMMARY:
==32055== in use at exit: 0 bytes in 0 blocks
==32055== total heap usage: 2 allocs, 2 frees, 127 bytes allocated
==32055==
==32055== All heap blocks were freed -- no leaks are possible
==32055==
==32055== For counts of detected and suppressed errors, rerun with: -v
==32055== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
|