Thread: Free a pointer

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    4

    Free a pointer

    Hi all!
    I am an new bie!
    I have an error, could you should why it wrong and how to fix it!
    My sample code:
    Code:
    typedef struct _pointer_note{ 
    	char name[10];
    	char *loai;
    	int  data;
    	float *stack_next;
    }pointer;
    
    int main()
    {
     pointer p1; //declare a  pointer type variable
     p1.loai = (char*)malloc(sizeof(char)*256);//
     strcpy(p1.loai,"hello world");
     // Do some thing
    free(p1.loai);//free a pointer
    return 0;
    }
    When run program, an error "DAMAGE: after normal block(#42)"

    Help me!
    Thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  4. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM