int matrix with pointers in C - memory allocation confusion

后端 未结 7 1328
春和景丽
春和景丽 2020-12-18 05:01

I\'m having some issues with producing an int matrix without creating memory leaks. I want to be able to make a given (global) matrix into any size dynamically via read_matr

7条回答
  •  情话喂你
    2020-12-18 05:33

    Freeing the memory doesn't make it go away, it just means that another allocation might grab that same chunk of memory. Whatever you put in it will still be there until something else overwrites it.

    Also, you're not freeing everything you allocated. You're only freeing the array of pointers and the first row. But even if you free everything correctly, you would still have the same effect.

    If you want to create a "bus error" you need to point to memory that doesn't belong to your process. Why do you want to do that anyway?

提交回复
热议问题