LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2005, 08:58 AM   #1
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: openSUSE Tumbleweed
Posts: 209

Rep: Reputation: 30
free pointer


hi

habitually, i free when i do a malloc...
but i see sometime on the web some people who free pointer created without maloc

Code:
void checkIO()
{
	struct conn *conn_ptr = conns;

	while(conn_ptr != NULL) {
		if(fdIsReadable(conn_ptr->fd))
			doIO(conn_ptr);
		conn_ptr = conn_ptr->next;
	}
}
here some people will do after the while:

Code:
free(conn_ptr );
thanks
 
Old 02-23-2005, 10:07 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Perhaps conns is allocated somewhere. It's the same as doing like this:
Code:
{
  int *a = malloc(sizeof(int));
  int *b = a;

  free(b);
}
b and a both point to the same memory so you can pass either one to free().
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Glibc free() invalid pointer pierre-luc Programming 3 11-13-2005 09:04 PM
pass pointer,, return pointer??? blizunt7 Programming 3 07-23-2005 02:36 PM
returning data to main() via a pointer to a pointer. slzckboy Programming 3 05-30-2005 02:20 PM
OpenOffice.org *** glibc detected *** free(): invalid pointer: 0x41481c94 *** Artanicus Linux - Software 2 02-19-2005 08:04 PM
hot to set value of pointer to pointer to a structure in C alix123 Programming 2 11-17-2004 07:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration