472,958 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Detecting dangling memory references

My experience has always been that you're SOL when trying to safely
detect and stop references to dangling memory (non-null pointers to
free'ed blocks) at runtime (C99, Linux).

Maybe somebody clever has worked this out, though?

(Apologies to those who find the question off topic for CUP or CLC)
Nov 14 '05 #1
5 1924
rh***@hotmail.com wrote...
My experience has always been that you're SOL when trying to safely
detect and stop references to dangling memory (non-null pointers to
free'ed blocks) at runtime (C99, Linux).

Maybe somebody clever has worked this out, though?

(Apologies to those who find the question off topic for CUP or CLC)


Before somebody says "fix your code," the pointer is coming to me
from a library. Valgrind is claiming it's a non-null pointer to a
block that hasn't been allocated.
Nov 14 '05 #2
Richard wrote:
My experience has always been that you're SOL when trying to safely
detect and stop references to dangling memory (non-null pointers to
free'ed blocks) at runtime (C99, Linux).

Maybe somebody clever has worked this out, though?

(Apologies to those who find the question off topic for CUP or CLC)


There is electric fence that can help with this too !!
--
Karthik.
Humans please 'removeme_' for my real email.
Nov 14 '05 #3
joe
Richard <rh***@hotmail.com> writes:
rh***@hotmail.com wrote...
My experience has always been that you're SOL when trying to safely
detect and stop references to dangling memory (non-null pointers to
free'ed blocks) at runtime (C99, Linux).

Maybe somebody clever has worked this out, though?

(Apologies to those who find the question off topic for CUP or
CLC)

You'll probably get complaints from clc, but it's certainly on topic
in cup.
Before somebody says "fix your code," the pointer is coming to me
from a library. Valgrind is claiming it's a non-null pointer to a
block that hasn't been allocated.


Then you might want to send that output to the maintainers of the
library and suggest they look into it. What else can you do if you
don't control the code?

Depending on your platform there are probably other memory checkers
you could use. What OS are you doing this on?

Joe
--
"Surprise me"
- Yogi Berra when asked where he wanted to be buried.
Nov 14 '05 #4
Richard wrote:
rh***@hotmail.com wrote...
My experience has always been that you're SOL when trying to
safely detect and stop references to dangling memory (non-null
pointers to free'ed blocks) at runtime (C99, Linux).

Maybe somebody clever has worked this out, though?

(Apologies to those who find the question off topic for CUP or CLC)

Valid for cup I expect, and should be of interest here on clc.

Before somebody says "fix your code," the pointer is coming to
me from a library. Valgrind is claiming it's a non-null pointer
to a block that hasn't been allocated.


You may want to look at my nmalloc for DJGPP. It is close to
standard C, but depends on various things (including pointer
arithmetic and sbrk) and the variadic macros are built around the
gcc (non-standard) technique. Those macros are only needed for
debuggery, but the variadic nature makes it impossible to just
define them out, thus you need gcc.

The point of this is that nmalloc has internal checks for
validity. Some of them are turned off by "#define SAVEMEMORY =
1". I originally had this enabled, which installed guard values
above and below the actual memory assignments, and with it
restored it should be possible to create an "int
_nmalloc_validptr(void *);" to provide close assurance of
validity, by checking that the block is assigned, with valid
forward and backwards pointers, and that the guards have not been
mangled.

If your existing code can be compiled under DJGPP you could try
most of this out with no changes. See the malldbg module in
nmalloc.

<http://cbfalconer.home.att.net/download/nmalloc.zip>

--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - Bush.
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
Nov 14 '05 #5
jo*@invalid.address wrote in message news:<m3************@invalid.address>...
Richard <rh***@hotmail.com> writes:
rh***@hotmail.com wrote...
My experience has always been that you're SOL when trying to safely
detect and stop references to dangling memory (non-null pointers to
free'ed blocks) at runtime (C99, Linux).
C99? Are you sure?
Maybe somebody clever has worked this out, though?

(Apologies to those who find the question off topic for CUP or
CLC)


You'll probably get complaints from clc, but it's certainly on topic
in cup.


It's on topic in clc and the answer is 'yes, you're sol'. Answers from
cup involving implementation specific codings or third party libraries
will be off topic to clc though, so setting followups would be
appreciated.

--
Peter
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Aravind | last post by:
I would like to know in what manner dangling pointers affect the security of a application developed using C++.What are the loopholes that are created by dangling pointers and how they could be...
11
by: John | last post by:
Hi: Below is a simple code: class link1 { public: link1(); link1(int &b1, double &b2); int* a1;
1
by: Nick Keighley | last post by:
I saw this in some code I'm maintaining. Is it a bad idea? class T { public #: T () i_mem(0) { } T (T2 &t2) i_mem(0), t2_ref (t2)
6
by: Tony Johansson | last post by:
Hello Experts! I'm reading in a book about C++ and the book says common errors is "A function should not return a constant references to its parameter passed by constant references" Why? Here...
6
by: Matthias Kaeppler | last post by:
Hi, I have a question regarding references, and their chance to "dangle" (if that's possible at all): Say I have a collection ob objects, and I take a reference to one of them. Now I sort...
20
by: __PPS__ | last post by:
Hello everybody in a quiz I had a question about dangling pointer: "What a dangling pointer is and the danger of using it" My answer was: "dangling pointer is a pointer that points to some...
9
by: prabhat143 | last post by:
Hi, I was recently asked to write a function in C that would detect if memory is corrupted. I had no clue about the solution but what I believe is that the solution is not complicated. Does...
1
by: sekhar_ps | last post by:
if we store some value at the place in memory which void pointer references then we increment void pointer this leads to dangling pointer?can any one explain whats the reasons for dangling pointer
10
by: Belebele | last post by:
Suppose that I have a method that returns references to "elements" in an iterator, and a method to advance the iterator: class Element { /* ... */ }; class Iterator { public: Element&...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.