473,563 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1966
rh***@hotmail.c om 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.c om 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.c om 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_validp tr(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.add ress wrote in message news:<m3******* *****@invalid.a ddress>...
Richard <rh***@hotmail. com> writes:
rh***@hotmail.c om 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
3072
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 exploited by hackers?. Aravind
11
1925
by: John | last post by:
Hi: Below is a simple code: class link1 { public: link1(); link1(int &b1, double &b2); int* a1;
1
1852
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
1950
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 I have written a method that has exactly this which is the parameter is passed by constant references and I return constant references what is it...
6
2081
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 this collection, or invoke whatever action it takes to copy around the elements in the collection. What happens to the reference?
20
6535
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 area of ram that's not reserved by the program. Accessing memory through such pointer is likely to result in core dump (memory access violation)"
9
6863
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 anybody know how to write such a function? Regards, Prabhat
1
4414
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
1730
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& operator*() const; Iterator& operator++();
0
7659
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7580
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.