Access violation in free()
- From: spl <splender.dev@xxxxxxxxx>
- Date: Sat, 01 Sep 2007 23:22:35 -0000
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);
}
.
- Follow-Ups:
- Re: Access violation in free()
- From: CBFalconer
- Re: Access violation in free()
- From: Richard
- Re: Access violation in free()
- From: Martin Ambuhl
- Re: Access violation in free()
- From: Ian Collins
- Re: Access violation in free()
- Prev by Date: Re: Porting C software
- Next by Date: Re: Porting C software
- Previous by thread: Matrix as an argument
- Next by thread: Re: Access violation in free()
- Index(es):
Relevant Pages
|