Dynamic memory C, realloc exeption : i try write code with dynamic memory, and faced with the problem, 
when called realloc() in genPointLinkArray() program throws exeptions: "ConsoleApplication1.exe has triggered a breakpoint.". i use Visual Studio 15 and run program in a Debug mode

    struct graphPoint
    {
    	point p;
    	int value;
    };
    struct graphLink
    {
    	point start;
    	graphPoint end;
    };
    graphLink* genPointLink(char map[10][10], point start, graphPoint primaryPoint[22], int *linksNum)
    {
    	graphLink *lin = (graphLink*)0;
    	(*linksNum) = 0;
    	for (int i = 0; i < 22; i++)
    	{
    		if (!ifWay(map, start, primaryPoint[i].p))
    		{
    			(*linksNum)++;
    			if(*linksNum == 1)
    				lin = (graphLink*)malloc(sizeof(graphLink));
    			else
    			{
    				lin = (graphLink*)realloc(lin, (*linksNum) * sizeof(graphLink));
    			}
    			(lin + (*linksNum - 1))->start = start;
    			(lin + (*linksNum - 1))->end = primaryPoint[i];
    		}
    	}
    	return lin;
    
    }
    
    graphLink* genPointLinkArray(char map[10][10], graphPoint primaryPoint[22],  int *linksNum)
    {
    	graphLink *links = (graphLink*)0, *l;
    	int currentNum = 0;
    	*linksNum = 0;
    	for (int i = 0; i < 22; i++)
    	{
    		l = genPointLink(map, primaryPoint[i].p, primaryPoint, &currentNum);
    		if(currentNum != 0)
    			if (*linksNum == 0)
    				links = (graphLink*)calloc(currentNum, sizeof(graphLink));
    			else
    				links = (graphLink*)realloc(links, ((currentNum + *linksNum) * sizeof(graphLink)));
    		*linksNum = *linksNum + currentNum;
    		for (int i = 0; i < currentNum; i++)
    		{
    			links[*linksNum - 1 + i].end = l[i].end;
    			links[*linksNum - 1 + i].start = l[i].start;
    		}
    
    	}
    
    	for (int i = 0; i < *linksNum; i++)
    	{
    		printf("(%d ; %d) -> (%d ; %d) : %d\n", links[i].start.x, links[i].start.y, links[i].end.p.x, links[i].end.p.y, links[i].end.value);
    	}
    
    	return links;
    }