Re: [Valgrind-users] Detecting all dangling pointers at exit
On Wed, 2018-12-26 at 10:15 +, Kumara, Asanka wrote: > Hi, > Is there a way to detect ALL dangling pointers (at exit) in valgrind ? > > e.g. > > char* globalVar; > > void main() > { > char* z1 = new char[10]; > char* z2 = z1; > globalVar = z2; > > delete[] z1; > > } > > At exit of the program say that “globalVar” holds a pointer to a freed memory. No, this feature does not exist. I do not think that it would be very difficult to implement: it would basically be the same algorithm as the leak search, but instead of searching for pointers pointing at allocated blocks, the search should find the pointers pointing at recently freed blocks. That being said, it means that you will only find the dangling pointers pointing in the recently freed blocks list, as dimensioned with --freelist-vol= volume of freed blocks queue [2000] So, you would only have a guarantee to detect ALL dangling pointers if the free list volume is big enough to hold all blocks that were freed during the run of the program. And of course, as valgrind implements an optimistic leak search, you would get an 'optimistic dangling pointer search' : on a 64 bits platform, any aligned 8 bytes (e.g. integer, char array, ...) might be considered by 'luck' as pointing to a recently freed block, giving a false positive dangling pointer. Philippe ___ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users
[Valgrind-users] Detecting all dangling pointers at exit
Hi, Is there a way to detect ALL dangling pointers (at exit) in valgrind ? e.g. char* globalVar; void main() { char* z1 = new char[10]; char* z2 = z1; globalVar = z2; delete[] z1; } At exit of the program say that "globalVar" holds a pointer to a freed memory. Please read these warnings and restrictions: This e-mail transmission is strictly confidential and intended solely for the ordinary user of the e-mail address to which it was addressed. It may contain legally privileged and/or CONFIDENTIAL information. The unauthorised use, disclosure, distribution and/or copying of this e-mail or any information it contains is prohibited and could, in certain circumstances, constitute a criminal offence. If you have received this e-mail in error or are not an intended recipient please inform the London Stock Exchange immediately by return e-mail or telephone 020 7797 1000. LSEG may collect, process and retain your personal information for its business purposes. For more information please see our Privacy Policy. We advise that in keeping with good computing practice the recipient of this e-mail should ensure that it is virus free. We do not accept responsibility for any virus that may be transferred by way of this e-mail. E-mail may be susceptible to data corruption, interception and unauthorised amendment, and we do not accept liability for any such corruption, interception or amendment or any consequences thereof. Calls to the London Stock Exchange may be recorded to enable the Exchange to carry out its regulatory responsibilities. London Stock Exchange plc 10 Paternoster Square London EC4M 7LS Registered in England and Wales No 2075721 ___ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users