int* returnPathInfo(int u, int numNodes)

{

int input_u = u;

int i = 0;

int *S = (int*)malloc(sizeof(int) * numNodes + 1);


while(prev[u] != -1)

{

S[i++] = u;

u = prev[u];

}


while (i < (numNodes + 1))

{

S[i++] = -1; //"-1" is value of stack-top

}

//while (--i >= 0) printf("%d ", (S[i])); //print path as node number for debugging


return S;

}


void freeDijkstra(int *S)

{

free(S);

free(dist);

free(prev);

}


Debug Error!


Program: ...sual Studio 2017\Projects\dijkstra_bus\Debug\dijkstra_bus.exe


HEAP CORRUPTION DETECTED: after Normal block (#134) at 0x0102F198.

CRT detected that the application wrote to memory after end of heap buffer.



(Press Retry to debug the application)




갓글에 HEAP CORRUPTION DETECTED검색 해보니깐


연관 검색으로 ~ free가 나왔고


나도 free하는 과정에서 저 오류가 나와서 저걸로 검색해 보니깐


free가 할당해 준 공간을 넘어서 까지 free하려고 하면 이런 오류가 나온다고 함




해결 방법으로는 문자 길이의 1만큼 더 할당해 주고


끝에 널값 너으라는데


string도 아니고 저어는 어떡하죠?