Detecting dangling memory references

Discussion in 'C Programming' started by Richard, May 3, 2004.

  1. Richard

    Richard Guest

    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)
     
    Richard, May 3, 2004
    #1
    1. Advertising

  2. Richard

    Richard Guest

    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.
     
    Richard, May 3, 2004
    #2
    1. Advertising

  3. Richard

    Karthik Guest

    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.
     
    Karthik, May 3, 2004
    #3
  4. Richard

    Guest

    Richard <> writes:

    > 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.
     
    , May 3, 2004
    #4
  5. Richard

    CBFalconer Guest

    Richard wrote:
    > 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.
     
    CBFalconer, May 4, 2004
    #5
  6. ess wrote in message news:<>...
    > Richard <> writes:
    > > 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
     
    Peter Nilsson, May 4, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rootz anabo
    Replies:
    0
    Views:
    476
    rootz anabo
    Feb 3, 2005
  2. Hans Van den Eynden

    dangling reference

    Hans Van den Eynden, Oct 16, 2004, in forum: Java
    Replies:
    1
    Views:
    2,878
    Joona I Palaste
    Oct 16, 2004
  3. Tony Johansson

    dangling references?

    Tony Johansson, Apr 6, 2005, in forum: C++
    Replies:
    6
    Views:
    577
    Alf P. Steinbach
    Apr 7, 2005
  4. Matthias Kaeppler

    Dangling references?

    Matthias Kaeppler, Oct 10, 2005, in forum: C++
    Replies:
    6
    Views:
    446
  5. Jarek Blakarz
    Replies:
    2
    Views:
    372
    Jarek Blakarz
    Nov 6, 2012
Loading...

Share This Page