422,538 Members | 2,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,538 IT Pros & Developers. It's quick & easy.

C++ find dangling pointer deletion

P: 25
Hello!

I am working on the source code of Blender and trying to contribute, mainly through bug fixes. Now I have a problem: I am using Visual Studio and Blender crashes because of a dangling pointer (value 0xDDDDDDDD). Now I want to find the place where it is deleted or freed. Are there tools or solutions for that? Most tools seem to only search for memory leaks and so on, those, which find dangling pointers, don't usually search the location where it is deleted or freed.
Thanks!

EDIT: Sorry for the double post, when I asked the first one, it somehow disappeared for a while, I thought it didn't work, asked this question again. Then the first question was visible again, but it seems like there is a problem with it, the sub site is wrong somehow.
1 Week Ago #1
Share this Question
Share on Google+
14 Replies


weaknessforcats
Expert Mod 5K+
P: 9,121
I believe a 0xDDDDDDDD is an uninitialized pointer. There is no DDDDDDDD address.

I believe Visual Studio inserts this phony address as a tip-off should the pointer never be initialized.
1 Week Ago #2

P: 25
Read this, there it says that 0xDDDDDDDD means deallocated memory. https://www.softwareverify.com/memory-bit-patterns.php
1 Week Ago #3

weaknessforcats
Expert Mod 5K+
P: 9,121
Yes. it's slowly coming back. 0xDDDDDDDD is deallocated memory and the 0xCCCCCCCC is the uninitialized pointer.

OK. So here goes. You need to stop using pointers. Instead you use a smart pointer. A smart pointer is a class enveloping a pointer such that each time a pointer object is copied the constructor increments a reference count and each time a pointer object is deleted, the destructor decrements the reference count. Should the reference count become zero, the destructor will delete the memory pointed at by the enveloped pointer. The reference count can only be zero when the current object(this) is the only object left.

There is a template for this in the C++ Standard Library. Look for std::shared_ptr.
1 Week Ago #4

P: 25
I know smart pointers, in fact, I am using them where I can already in my projects, but as I sad, this is work for an open-source software (Blender). So I can't really rewrite millions of lines of code to use smart pointers, I have to take the code as it is.
1 Week Ago #5

weaknessforcats
Expert Mod 5K+
P: 9,121
I would suggest that at least the pointer causing the crash be converted to a std::shared_ptr.

The behavior you describe indicates there is no reference count or shared logic protections on this thing.

By the time you write through this pointer and crash the site of the crash is nowhere near where the delete error occurred.

You might even consider logging allocations and deallocations during debug. At least this would give a stack map.

I suspect this will be a difficult thing to find.
1 Week Ago #6

P: 25
I just found that popular memory tools like asan (adress sanitizer) output the location where it is deleted. Now I only have to get one of those working on windows.
1 Week Ago #7

weaknessforcats
Expert Mod 5K+
P: 9,121
Is this Android or Linux? There are emulators for Windows 10. Install the emulator and launch through it.
1 Week Ago #8

P: 25
Can you explain it please a little bit more detailed? What do you mean with is this Android or Linux? And which emulators?
1 Week Ago #9

weaknessforcats
Expert Mod 5K+
P: 9,121
There's Cygwin. You recompile the Linux code on Windows 10 and run it.

For Android try: https://windowsreport.com/best-andro...rs-windows-10/


Of course, I cannot recommend any of these products. I can only point them out.
1 Week Ago #10

P: 25
I think I will try it with Dr. Memory or a similar tool which is windows compatible.
1 Week Ago #11

weaknessforcats
Expert Mod 5K+
P: 9,121
Let me know what happens.
1 Week Ago #12

P: 25
Well, it seems to be working, but I clearly have to learn how to supress and whitelist errors, because it counts more than 2.000.000 just on Blender startup ��
6 Days Ago #13

weaknessforcats
Expert Mod 5K+
P: 9,121
Often the first error triggers a slew of other errors and this cascades into a huge mess.

If you can, fix only the first error and then rebuild.
5 Days Ago #14

P: 25
I don't think so, the warnings are spread all over blender. But the problem is, the whitelist docs for dr. Memory are a bit... bot that detailed. It would be cool if I could whitelist only one file. Of course, I can suppress all other error types too, vut there seem to be still many uninitialized accesses or at least many possibilities for them.
4 Days Ago #15

Post your reply

Sign in to post your reply or Sign up for a free account.