- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Memory management
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
Forums
Discussions
Discussions
Discussions
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
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
07-16-2009 01:01 AM
07-16-2009 01:01 AM
I have the following doubt about variables memory management in C.
I have a function returning a pointer to "char":
char *func(){
....
char *x;
....
x = malloc(20);
....
return x;
}
and then I use it in the following way:
amb_buff = char[100];
...
for( ; ;)
{
...
sprintf(amb_buff, "%s", func());
...
}
My question is about the memory allocated for "x" var by "malloc" in the routine:
- is it freed after the "func" function return,
- or, at each iteration of the "for" cycle, a new 20 bytes of memory are added to the process memory amount?
In few words: does the total process memory increase undefinitely?
Thanks
Giuseppe Fedele
Solved! Go to Solution.
- Tags:
- leak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2009 01:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2009 03:52 AM
07-16-2009 03:52 AM
Re: Memory management
To add, as noted already, calling 'malloc()' [or its cousins] allocates memory to the 'heap' (a program's memory pool) while 'free()' returns that memory to the heap. This is designed for performance and is normal behavior. That is, the freed memory is given to the program's heap but _not_ to the operating system at large until the program finally terminates.
The heap can grow up to the size specified by 'maxdsiz' for 32-bit processes or up to 'maxdsiz_64bit' for 64-bit processes.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2009 04:01 AM
07-16-2009 04:01 AM
Re: Memory management
procedure func: warning #20200-D: Potential null pointer dereference through x is detected (null definition:itrc_leak.c, line 5)
procedure main: warning #20201-D: Memory leak is detected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2009 05:12 AM
07-20-2009 05:12 AM
Re: Memory management
they are not as slow as you might think and help to maintain your sanity and program stability!!