Segfaults on pointer deletion


 
Thread Tools Search this Thread
Top Forums Programming Segfaults on pointer deletion
# 8  
Old 03-09-2011
Please post your code. I can only guess what might be going wrong at this point.
Quote:
Originally Posted by ctote
1. Yes, it's the same pointer
You've checked the value the pointer started as? You're sure it didn't mysteriously change anywhere? How did you check?
Quote:
2. Destructor doesn't do anything
Literally nothing?
Quote:
I'm not sure if there's a special way to delete an object that contains arrays?
I'm not sure what this has to do with my question, since objects you created with new aren't stack objects, but no. There's no special way. If you made it with new, you can free it with delete.
Quote:
Is it invalid to delete an object that contains pointers to NULL?
No. Delete doesn't check or use any of the members, that's the destructor's job.
Quote:
The object I'm deleting has 3 members that are pointing to 0x0000000.
delete doesn't care about the contents. What matters is what the destructor does.

I used up everything my crystal ball had to offer in the last post. I can't and won't answer any more of your questions until you post your code.
# 9  
Old 03-10-2011
Bug

Quote:
Originally Posted by ctote
Hey Everyone,

I have a check similar to this:
Code:
if (ptr)
{
   delete ptr;
   ptr = null;
}

When I'm debugging in AIX (using dbx), if I attempt to print the value of 'ptr' it says "ptr is not defined" - however, it still enters that if block. So, I'm getting segfaults on the delete statement. Can anyone suggest why the if() block is entered?
Hi ctote,

if a ptr is NOT NULL, then it is true, (for ex. containing a junk values, aka bad pointer). if you did not define your ptr to NULL when you declare/free them, you should be careful about re-using them. Try to print the 'ptr' before entering the 'if block' and after you exiting the 'if block' and see if there is any difference.

Cheers,
Gaurav.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

advanced deletion

How can i delete the contents of the directory except one file? (8 Replies)
Discussion started by: proactiveaditya
8 Replies

2. Shell Programming and Scripting

Deletion of records

Hi, I have file with footer (5records) at end of the file. I want to delete the footer as well as the empty records between the main records and footer record.(The gap between main records and Footer records is dynamic) Example: MainRecord1 "115494",","FAELD","CT","... (12 Replies)
Discussion started by: vsairam
12 Replies

3. Shell Programming and Scripting

Deletion of a particular character

How to delete a particular character in a file and then removing the spaces created by that removal.I am working with a text file containing nucleotide sequences. I have tried sed command but it replaces N with spaces. example:I want to delete all the N without creating a space after its ... (1 Reply)
Discussion started by: ankitachaurasia
1 Replies

4. Programming

pass a pointer-to-pointer, or return a pointer?

If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it: (1) one is to pass a pointer-to-pointer parameter, like: int my_malloc(int size, char **pmem) { *pmem=(char *)malloc(size); if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies

5. Forum Support Area for Unregistered Users & Account Problems

deletion ofsunburntYux

Could you please close SunburntYux as I would like to use the emaill address on this account to register FloridaBSD, (0 Replies)
Discussion started by: SunBurntYux
0 Replies

6. Shell Programming and Scripting

Help: deletion of record

I have created a address book file. Insertion of Record (using >> symbol)and searching of record (using grep command) into the address book is also working correctly. Now I want to delete a record into a file. Any body can help me in this case without using sed and awk18 18. Thanks and best... (24 Replies)
Discussion started by: murtaza
24 Replies

7. UNIX for Advanced & Expert Users

Deletion of Logs

Can someone suggest on this script : let's say the logs files are available for Jan 07, Dec 06, Nov 06, Oct 06 the script should identify the latest months logs, i.e Jan 07 it should then delete anything older than 2 months, which will be logs for Nov 06 & Oct 06. (40 Replies)
Discussion started by: srirams
40 Replies

8. Programming

memcpy segfaults, but not in windows

Hi Having a lil trouble with a rather simple application I'm writing. It so happens that I have to copy some data using memcpy() and so far I've been doing just fine compiling it with VC.Net and running it on Windows XP. Now I'm trying to port the thing to Solaris (which shouldn't really be too... (3 Replies)
Discussion started by: khoma
3 Replies

9. Shell Programming and Scripting

Regarding deletion of old files

Hi, I have a list of directories which contain old files that are to be deleted. I put the list of all directories in a txt file and it is being read by a script Iam searching for the files older than 60 days using mtime and then deleting it But all the files are getting deleted... (3 Replies)
Discussion started by: Chidvilas
3 Replies

10. Post Here to Contact Site Administrators and Moderators

Account Deletion...

Please delete my account? Thanks, so very much, really. (2 Replies)
Discussion started by: spaceshiporion
2 Replies
Login or Register to Ask a Question