请看一下下面这段代码有什么问题。
void GetMemory(char *p) {
p = (char *)malloc(100);
}
void Test(void) {
char *str = nullptr;
GetMemory(str);
strcpy(str, "hello world");
printf(str);
}
● 修改形参的值并不会改变实参的值,所以调用GetMemory之后,str依然为空指针;
● 在GetMemory和Test中,没有malloc对应的free,造成内存泄漏。
