- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- realloc() error
Operating System - HP-UX
1753720
Members
4790
Online
108799
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
10-02-2001 08:45 PM
10-02-2001 08:45 PM
Hey all,
does anyone have any information (other than man pages) or experience with realloc() failing on HPUX
11.00? 32Bit and 64Bit
This problem occurs under both gcc and ansiC.
for (i = 0; i < 3; i++) {
if ((varspace[i] = (struct VSPACE *)realloc(varspace[i],sizeof(s
truct VSPACE))) == NULL) {
perror("malloc(1)");
exit(1);
}
memset((char *)varspace[i], 0, (int)sizeof(varspace[i]));
}
This is a tiny snippet of the offending code.
A dump file (sort of tracing what program does) comes out with the following:
Begin: {(173) END: }(175)
[1]#(43)[1]S(123)[1]:(72)[1]n(156)[1]a(141)[1]m(155)[1]e(145)[1]2(62)[1]:(72)[1]
"(42)[1] (40)[1]"(42)[1]:(72)[1]1(61)[1]:(72)[1]0(60)[1] (40)[1]}(175)
STRINGPROCESS FUNCTION
Stdup string is 1074305086 and end is 1074305103
(#S:name2:" ":1:0 )
which is normal (for what this program does).
Has anyone had any problems with realloc()?
Scott.
does anyone have any information (other than man pages) or experience with realloc() failing on HPUX
11.00? 32Bit and 64Bit
This problem occurs under both gcc and ansiC.
for (i = 0; i < 3; i++) {
if ((varspace[i] = (struct VSPACE *)realloc(varspace[i],sizeof(s
truct VSPACE))) == NULL) {
perror("malloc(1)");
exit(1);
}
memset((char *)varspace[i], 0, (int)sizeof(varspace[i]));
}
This is a tiny snippet of the offending code.
A dump file (sort of tracing what program does) comes out with the following:
Begin: {(173) END: }(175)
[1]#(43)[1]S(123)[1]:(72)[1]n(156)[1]a(141)[1]m(155)[1]e(145)[1]2(62)[1]:(72)[1]
"(42)[1] (40)[1]"(42)[1]:(72)[1]1(61)[1]:(72)[1]0(60)[1] (40)[1]}(175)
STRINGPROCESS FUNCTION
Stdup string is 1074305086 and end is 1074305103
(#S:name2:" ":1:0 )
which is normal (for what this program does).
Has anyone had any problems with realloc()?
Scott.
Solved! Go to Solution.
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 06:28 AM
10-03-2001 06:28 AM
Solution
Hi Scott:
I've regularly used realloc() and had no problems like you describe. I did note that in your code snippet varspace[i] was undefined in the call to realloc. I assume in the real code that initially varspace[i] is NULL so that realloc can revert to malloc behavior.
The other thing that can really create havoc is the case where you initially malloc or calloc or realloc a space that has pointers pointing within the allocated space. Now consider the case where you then use realloc to expand the original space. If realloc is able to expand in place (as it often does) then no worries; however, if realloc cannot expand in place it creates a new space and copies the contents of the old space to the new space and the old space is returned to the heap. Pointers which still refer to addresses within the old space now point to the Twilight Zone.
Food for thought, Clay
I've regularly used realloc() and had no problems like you describe. I did note that in your code snippet varspace[i] was undefined in the call to realloc. I assume in the real code that initially varspace[i] is NULL so that realloc can revert to malloc behavior.
The other thing that can really create havoc is the case where you initially malloc or calloc or realloc a space that has pointers pointing within the allocated space. Now consider the case where you then use realloc to expand the original space. If realloc is able to expand in place (as it often does) then no worries; however, if realloc cannot expand in place it creates a new space and copies the contents of the old space to the new space and the old space is returned to the heap. Pointers which still refer to addresses within the old space now point to the Twilight Zone.
Food for thought, Clay
If it ain't broke, I can fix that.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP