Re: [LIP] Query:tcsetattr on disk file descriptor and free function issue.
"Josy P. Pullockara" <[email protected]>
| Newsgroups | gmane.user-groups.linux.india.programmers |
|---|---|
| Organization | National Aerospace Laboratories |
| Message-ID | <[email protected]> |
On Mon, 2004-01-19 at 13:16, Binand Sethumadhavan wrote:
> On Mon, 2004-01-19 at 12:27, Shehjar Tikoo wrote:
> > Should'nt the fprintf statement below cause a
> > segmentation fault:
> >
> > freepthead(head);
> > fprintf(stdout,"%s\n",head->path);
I think in your case by trying to free it in a function you are probably
not doing what you want to do. Read below for what mistake you may be
doing, which Binand probably overlooked.
On Mon, 2004-01-19 at 13:16, Binand Sethumadhavan wrote:
> Not necessarily. OTOH, if your freepthead() function were like:
>
> free(head);
> head = NULL;
>
> then this will certainly dump core ("Dereferencing a null pointer").
This may not set the value of head to "0" as "head" is a local variable
in the function freepthead(). In order to set "head" to "0" use as
follows:
void
freepthead(struct pthead **h) /* notice the pointer to pointer */
{
...
free(*h);
*h = 0;
}
Then your call
freepthead(&head); /* notice the pointer to head */
fprintf(stdout,"%s\n",head->path);
will guarantee a segmentation fault.
Regards.
--
Josy P. Pullockara <[email protected]>
National Aerospace Laboratories
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn