/* DECLARED FUNCTIONS */
char *DetectDevice(void);
int main(int argc, char *argv[])
{
char *PathToDevice;
PathToDevice = DetectDevice();
...
if(close(fd) == -1)
{
printf("Error Closing Port");
}else
{
printf("whihi!");
free(PathToDevice);
}
return 0;
}
char *DetectDevice(void)
{
char *Usbs = malloc(1024);
Usbs = "/dev/ttyUSB1";
return Usbs;
}
错误消息:* 检测到 glibc * ./test: free(): invalid pointer: 0xbec1b504
顺便说一句……这个程序是在树莓派上编译的!