malloc double free behaviour

前端 未结 5 728
甜味超标
甜味超标 2020-12-21 14:19

The GNU manual page for malloc defines that when free() called twice with the same pointer (that was previously allocated by malloc())

5条回答
  •  庸人自扰
    2020-12-21 14:30

    The C99 standard states the following for undefined behaviour (under the Terms and definitions section):

    Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).

    In summary: anything can happen. The worst case is for the program to behave as expected.

提交回复
热议问题