diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-07-01 02:12:43 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-07-01 02:12:43 +0000 |
commit | 13ea39a34766fcbecd96ab94bcdf798b08e9bb60 (patch) | |
tree | 1e1463b03838a6f36868a4dafc7e652358a51857 /libshouldbeinlibc/localhost.c | |
parent | 1f8d504f631531c199d7c6154a0dc442d80ea4a7 (diff) | |
parent | 7e15f3d69a83a34ac62cbbee944a0bfbfa92724e (diff) |
Merge branch 'master' into xkb
Conflicts:
config.make.in
configure.in
Diffstat (limited to 'libshouldbeinlibc/localhost.c')
-rw-r--r-- | libshouldbeinlibc/localhost.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/libshouldbeinlibc/localhost.c b/libshouldbeinlibc/localhost.c index f0c67541..f0225116 100644 --- a/libshouldbeinlibc/localhost.c +++ b/libshouldbeinlibc/localhost.c @@ -39,18 +39,27 @@ localhost () errno = 0; if (buf) { + char *new; buf_len += buf_len; - buf = realloc (buf, buf_len); + new = realloc (buf, buf_len); + if (! new) + { + free (buf); + buf = 0; + errno = ENOMEM; + return 0; + } + else + buf = new; } else { buf_len = 128; /* Initial guess */ buf = malloc (buf_len); + if (! buf) + { + errno = ENOMEM; + return 0; + } } - - if (! buf) - { - errno = ENOMEM; - return 0; - } } while ((gethostname(buf, buf_len) == 0 && !memchr (buf, '\0', buf_len)) || errno == ENAMETOOLONG); |