Access violation in free()



I am getting access violation in the below program for the free()
call, Whats wrong here and how to rectify it?
----------------------------------
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>

char * CopyString(char *s)
{
int length = strlen(s);
char * t = (char *)malloc(length);
strcpy(t,s);
return t;
}


void main()
{
char *destStr;
char *sourceStr = "Test";
destStr = CopyString(sourceStr);
printf("Destination String : %s\n", destStr);
free(destStr);

}

.



Relevant Pages

  • Re: Access violation in free()
    ... First fix the various errors, ... char * CopyString ... main always returns an int. ... destStr = CopyString; ...
    (comp.lang.c)
  • Re: Access violation in free()
    ... Better: char *CopyString ... int main ... destStr = CopyString; ...
    (comp.lang.c)
  • Re: Access violation in free()
    ... char *CopyString ... int main ... destStr = CopyString; ...
    (comp.lang.c)
  • Re: Access violation in free()
    ... Whats wrong here and how to rectify it? ... char * CopyString ... Drop the cast. ... Most environments use int main. ...
    (comp.lang.c)
  • SSPI Kerberos for delegation
    ... const char *tokenSource, const char *name = NULL, ... DWORD bufsiz = sizeof buf; ... int n = ib.cbBuffer; ... // wserr() displays winsock errors and aborts. ...
    (microsoft.public.dotnet.framework.remoting)