Free a pointer

This is a discussion on Free a pointer within the C Programming forums, part of the General Programming Boards category; Hi all! I am an new bie! I have an error, could you should why it wrong and how to ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,755
    Already asked and answered.
    Free a pointer
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 03:29 PM
  3. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 04:47 PM
  4. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 04: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, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21