- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Question on new() !!
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2002 01:41 AM
тАО09-14-2002 01:41 AM
Question on new() !!
HP aC++ B3910B A.01.23
HP aC++ B3910B A.01.19.02 Language Support Library
We have a struct like this -
struct Seqof_GSMObjInstance
{
long x;
char *octets;
struct Seqof_GSMObjInstance *next;
};
There is a function which allocated memory for this structure like this -
Seqof_GSMObjInstance * GSMObjInstance_tBin::alloc()
{
Seqof_GSMObjInstance *aPtr = new Seqof_GSMObjInstance();
memset(aPtr, 0, sizeof(SeqObjInst) );
return aPtr;
}
The program was compiled on HP-UX 10.20 but run on HP-UX 11.00.
We had a strange problem. The program crashed and we came to know from gdb through the analysis of the core file that, the program crashed at memset(). A portion of the stack trace is -
(gdb) bt
#0 0xc0f30130 in kill () from /usr/lib/libc.1
#1 0xc0e95b24 in raise () from /usr/lib/libc.1
#2 0xc0e75f38 in _sigaddset () from /usr/lib/libc.1
#3 0xc0e70d64 in abort () from /usr/lib/libc.1
#4 0xc9081958 in skSigMgmt::_OspSignalWrapper (signum=10) at /vob/osp.src/src/libskel/skel/skSigSensorThr.C:571
#5 0xc0d9e6bc in cma__sig_deliver () from /usr/lib/libcma.1
#6 0xc0d9eb78 in cma___sig_sync_term () from /usr/lib/libcma.1
#7
#8 0xc0e7227c in memset () from /usr/lib/libc.1
#9 0x2dd57c in GSMObjInstance_tBin::alloc (this=0x43c1f8dc)
To know, whether the call to new() was succesful, we executed further commands in gdb -
(gdb) f 9
#9 0x2dd57c in GSMObjInstance_tBin::alloc (this=0x43c1f8dc)
(gdb) info locals
aPtr = (struct Seqof_GSMObjInstance *) 0x8
(gdb) p *(struct Seqof_GSMObjInstance *) 0x8
Cannot access memory at address 0x8
From the above output, it is clear that, new() returned a corrupted address (0x8) and that is the reason the program crashed in memset().
The program does not crash every time in the above place but this has crashed atleast 3 times.
We checked the size of core (around 60MB) and it was much less than the kernel parameter - maxdsiz (200MB) set for the process. That means, the program did have enough memory in the heap.
Any idea, what went wrong in the above program ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2002 06:47 AM
тАО09-14-2002 06:47 AM
Re: Question on new() !!
I just slapped my developers and sysadmins on Thursday for using an ancient compiler and complaining about the results.
Start here:
http://h21007.www2.hp.com/dev/1,2583,,00.html
and here:
http://h21007.www2.hp.com/dev/technologies/topic/1,2608,10201,00.html
The latest version of the Compiler is A.03.35! (June 2002)
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-16-2002 06:22 AM
тАО09-16-2002 06:22 AM
Re: Question on new() !!
sizeof(SeqObjInst);
Did you mean this instead?
sizeof(Seqof_GSMObjInstance);
Jack
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-16-2002 09:24 PM
тАО09-16-2002 09:24 PM
Re: Question on new() !!
memset(aPtr, 0, sizeof(Seqof_GSMObjInstance) );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2002 06:41 AM
тАО09-17-2002 06:41 AM
Re: Question on new() !!
To work around the call to memset(), you can use aggregate initialization:
const Seqof_GSMObjInstance initial = { 0 };
Seqof_GSMObjInstance *aPtr = new Seqof_GSMObjInstance();
*aPtr = initial;
Jack
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 06:09 AM
тАО09-27-2002 06:09 AM
Re: Question on new() !!
Me too faced a similar problem. It goes like this. I was allocating memory to a class-pointer in a function and was assigning it to another pointer (of same class) that was passed as an arg of the function. The interesting aspect is it worked fine but gave me runaways at times.
So the memory allocation was directly performed on the pointer that was passwd as an arg and it worked fine.
I would suggest the following modification to your code.
Seqof_GSMObjInstance * GSMObjInstance_tBin::alloc(Seqof_GSMObjInstance **aPtr)
{
*aPtr = new Seqof_GSMObjInstance();
memset(*aPtr, 0, sizeof(SeqObjInst) );
return *aPtr;
}
Regards
Vishal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-03-2002 06:32 AM
тАО10-03-2002 06:32 AM
Re: Question on new() !!
= new Seqof_GSMObjInstance();
don't you need:
= new Seqof_GSMObjInstance;
without the "()"? There is no constructor function to invoke here; you just want to allocate memory for some structure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2002 02:35 AM
тАО10-23-2002 02:35 AM
Re: Question on new() !!
I would bet that you are using the object after deallocating memory.
Check it carefully.
Good luck
Adam