가변"malloc"메모리가 암시 적으로 해제됩니까? 고려
I이 sTmp
또 다른 변수를 지정하는 경우, 자동으로 해제 얻을이 변수로 할당 된 메모리를 수행하거나, 메모리 블록은 프로세스가 종료 될 때까지 (& 쓸모)가 할당 된 상태로 유지하지 malloc
정의 (char *)
의 sTmp
, ?
나 코드로 설명하자
는int main() {
char *sTmp = (char *) malloc (50);
char *sNew = strdup ("some text"); // length is less than 50
sTmp = sNew;
/* now sTmp points to sNew and it's length is 10 chars
I wonder, what happened to the allocated memory of 50 chars in the first line;
Does it get freed implicitly or remain allocated?
*/
}
메모리 누수가 발생했습니다. 메모리는 계속 할당됩니다. – perh