glibc detected, realloc(): invalid pointer

こ雲淡風輕ζ 提交于 2019-12-03 08:26:07

glibc is telling you you're passing in an address that couldn't have been returned from malloc/realloc. This is because you're passing in the address of the pointsAndName stack variable. You need to pass in the value, which is what you received from malloc. Also, whenever you call realloc, you should use a temporary variable. That way, if the realloc fails, you still free the original value.

struct figure *tempPtr = realloc(pointsAndname, temp * sizeof(struct figure));
if(tempPtr == NULL)
{
  // Handle allocation error...
  free(pointsAndname);
}
pointsAndname = tempPtr;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!