Thread: Realloc and Linux

  1. #16
    Registered User
    Join Date
    Jun 2008
    Posts
    93
    The program was not failing on the first realloc. It was tying up memory as the program repeated itself and eventually exhausting all memory. This is when it was crashing.

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Valgrind has to hold onto the memory so that it (and you) can spot any "use-after-free" memory problems you may have.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Registered User
    Join Date
    Jun 2008
    Posts
    93
    Aside from Valgrind I am still leaking memory due to constant reallocation. I guess this is just not a valid approach for a large amount of memory reallocation. I think my strategy will be to just malloc a very large cache of 256k blocks at the start of the daemon and then link them together as needed for files rather than realloc the individual blocks. I would imagine this would solve the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. realloc fails
    By beginner.c in forum C Programming
    Replies: 12
    Last Post: 04-27-2007, 08:42 AM
  2. Fast memory copy and realloc()
    By intmail in forum Linux Programming
    Replies: 3
    Last Post: 10-27-2006, 03:46 PM
  3. Realloc problem
    By franziss in forum C Programming
    Replies: 14
    Last Post: 01-25-2005, 10:21 AM
  4. confused about arrays
    By sal817 in forum C Programming
    Replies: 17
    Last Post: 09-20-2004, 03:45 PM
  5. Can't Realloc!
    By robblin in forum C Programming
    Replies: 10
    Last Post: 11-30-2001, 07:17 PM