[sheepdog] [sheepdog/sheepdog] c4b048: lib/util: Fix xrealloc to check out of memory erro...

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue Sep 27 10:00:31 CEST 2016


  Branch: refs/heads/master
  Home:   https://github.com/sheepdog/sheepdog
  Commit: c4b04841ac3f84ce37d753ee5e1c66804d951be7
      https://github.com/sheepdog/sheepdog/commit/c4b04841ac3f84ce37d753ee5e1c66804d951be7
  Author: Takashi Menjo <menjo.takashi at lab.ntt.co.jp>
  Date:   2016-09-20 (Tue, 20 Sep 2016)

  Changed paths:
    M lib/util.c

  Log Message:
  -----------
  lib/util: Fix xrealloc to check out of memory error correctly

The present xrealloc panics as "Out of memory" if realloc returns NULL.
However, man page of realloc[1] says that "If size was equal to 0, either
NULL or a pointer suitable to be passed to free() is returned." So xrealloc
can panic wrongly when size is equal to 0 and realloc returns NULL.

This commit fixes the issue described above. The man page also says that
"The UNIX 98 standard requires [..] realloc() to set errno to ENOMEM upon
failure." So I evaluate errno instead of returned value to check whether
out of memory really occurred or not.

[1] http://linux.die.net/man/3/realloc

Signed-off-by: Takashi Menjo <menjo.takashi at lab.ntt.co.jp>


  Commit: 551480c40bba72442f24add8263c32d5f4df38ea
      https://github.com/sheepdog/sheepdog/commit/551480c40bba72442f24add8263c32d5f4df38ea
  Author: Hitoshi Mitake <mitake.hitoshi at gmail.com>
  Date:   2016-09-27 (Tue, 27 Sep 2016)

  Changed paths:
    M lib/util.c

  Log Message:
  -----------
  Merge pull request #312 from tmenjo/fix-xrealloc-enomem

lib/util: Fix xrealloc to check out of memory error correctly


Compare: https://github.com/sheepdog/sheepdog/compare/b5a7613bdf0f...551480c40bba


More information about the sheepdog mailing list