mikeizbicki / ucr-cs100

open source software construction course
Other
485 stars 407 forks source link

Deleting memory #31

Closed kryne001 closed 10 years ago

kryne001 commented 10 years ago

I'm having a problem freeing my array of char**. i'm able to free the whole array without freeing each index first (which I know is wrong), but if I try to free each index, I get the following error in gdb:

malloc: * error for object 0x7fff5fbff3a9: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

I've gone through and checked that there was indeed a value there, which there was, and I think I'm allocating the memory for each index correctly, so I don't know where I should look to fix it.

kryne001 commented 10 years ago

my repository: https://github.com/kryne001/rshell

rgosh001 commented 10 years ago

hey man, I found this helpful for the similar problem i was having http://stackoverflow.com/questions/4193982/delete-a-pointer-to-pointer-as-array-of-arrays

kryne001 commented 10 years ago

yeah I just read that and I thought that's what I've been doing, but anyways I changed my allocation method from malloc to new and deallocation method from free to delete and still having the same problem when trying to delete each individual index.

rgosh001 commented 10 years ago

hmm, and you are allocating new memory for the whole array then individual index, correct?

kryne001 commented 10 years ago

yeah i allocate the whole array of char\ then go into a loop to allocate each index