HI all, In my c++ program, I did the following.

......
class thr
      {private:
               char *d;
......
        public:
               d =new char[35];
....
}
destructor has the line
delete [ ]d;

i get segmentation error 
 *** glibc detected *** /usr/bin/perl: free(): invalid next size (normal): 0x0000 000001bc7120 ***

But if I do the following in class,no error comes.

char *d;
char id[35];

Here I need not delete since it will automatically get deleted when it comes out of scope.I need this data in object functions.So is it wrong if I do this way?

help me out,pls.

Recommended Answers

All 3 Replies

Could you post a short program that demonstrates the problem (and that we can actually compile)?

This is not enoughf information. Post your code.

Hi, thanks for your time and interest.Actually it is a c++ program used as inline in my perl program.and so I was not able to attach the full code.sorry.
I found that the string in which I concatenated another string, had no null as last character and so the string was taken to a length till it could find a zero and so when deleted, it gave segmentation error.
thanks again
bubye.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.