473,563 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doubt related to free()

34 New Member
Hi All
I have a question related to free().

For example
A(char *buffer) call B(char *buffer)
B(char *buffer) in turn calls C(char *buffer)
C(char *buffer) in turn calls D(char *buffer)
D(char *buffer) in turn calls E(char *buffer)
and so on.........
I pass a pointer as a parameter from A()
A(char *buffer);
1) This buffer was freed somewhere in some function. (Deallocation could have done by B() or C() or D() or E() etc)
2) I did not set BUFFER=NULL after freeing up the buffer in any of the function.

Is there any way to know whether buffer was FREED or NOT when I return to A().
I believe BUFFER will be pointing to the location even if we free() the data.

Please let me know your response.

Thanks & Regards
Sathish Kumar
Jan 9 '09 #1
3 1188
JosAH
11,448 Recognized Expert MVP
Yep, the value of the buffer pointer isn't altered but it doesn't point to a valid memory region anymore; you have freed it so you can't use it anymore.

kind regards,

Jos
Jan 9 '09 #2
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
As Jos said it will be an invalid memory.
But if u want to find if there is a leak in code then go for Purify or boundschecker

raghu
Jan 9 '09 #3
Tassos Souris
152 New Member
You probably must get used to using pointer to pointers rather than pointers. For example when you have the head of a single linked list it is better to use that:
Expand|Select|Wrap|Line Numbers
  1. void freeList( struct List **head ){
  2.     // Do the free of all the nodes here
  3.  
  4.     // Set it safely to NULL
  5.     *head = NULL;
  6. }
  7.  
You must make it a rule that every free() is followed by a assignment to NULL:
Expand|Select|Wrap|Line Numbers
  1. free( ( void * )ptr );
  2. ptr = NULL;
  3.  
Jan 10 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11306
by: RK | last post by:
Hi, In my application, I need to copy data from an Excel file into a SQL table. The article related to this can be found at http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B306572 Using this,I am first extracting data from given excel file into a temporary DataTable. After making some operations on that DataTable (like...
2
1756
by: Lee Garrington | last post by:
Hey there, Is there a function that returns the amount of RAM free for memory allocation? Is there a function that will return the amount of memory your program currently uses through memory allocation? If not, is there any simple way of calculating this? Thx in advance
5
1479
by: CViniciusM | last post by:
Hello, The output of the code below is: number = 10 number = 0 (or other number except 15) Why the output of the second 'number' is not 15? Why the 'number' address is not changed? Thanks in advance, Vinicius.
8
3361
by: Chul Min Kim | last post by:
Hi, I got a BUS ERROR from one of my company's program. Let me briefly tell our environment. Machine : Sun E3500 (Ultra Sparc II 400Mhz CPU 4EA) OS : Solaris7 Compiler : Sun Workshop 5.0 cc complier I get "BUS ERROR" only when I execute the binary which builds
3
1254
by: orium69 | last post by:
Hi everyone! I have a doubt, when I free an alloced memory, how does the compiler know how many bytes I have alloced forward the pointer. eg: int *coiso; coiso=(int *)malloc(sizeof(int)*10);
122
4184
by: ivan | last post by:
hi all, if I have: if(A && B || C) which operation gets executed first? If I remeber well should be &&, am I correct? thanks
13
1574
by: Kamui Shirow | last post by:
Hello! I will write a snippet to illustrate my doubt: snippet 1: void foo( int l ) { char* tmp; tmp = (char*) malloc( l * sizeof( char ) );
8
2027
by: somenath | last post by:
Hi All, I have a doubt regarding the pointer assignment . Please have a look at the following program . #include<stdio.h> #include<stdlib.h> #define NAMESIZE 10 #define SAFE_FREE(t) if(t)\ {\
11
2906
by: whirlwindkevin | last post by:
I saw a program source code in which a variable is defined in a header file and that header file is included in 2 different C files.When i compile and link the files no error is being thrown.How is this possible.I thought it will throw "Variable redefinition Error". Giving the source code for reference.Please help me out on this... a.h...
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.