diff options
author | Shelley Vohr <shelley.vohr@gmail.com> | 2018-06-20 10:01:57 -0700 |
---|---|---|
committer | Santiago Gimeno <santiago.gimeno@gmail.com> | 2018-07-06 19:35:21 +0200 |
commit | 5124b27d355a868a07c51ca694c45b32b10f89b5 (patch) | |
tree | ffcd0664ea156ad315b775f6f60ab2a35e4a9efb /test/test-error.c | |
parent | b16d10a0177c32d6a9442d0758031cac8a5db36e (diff) | |
download | libuv-5124b27d355a868a07c51ca694c45b32b10f89b5.tar.gz libuv-5124b27d355a868a07c51ca694c45b32b10f89b5.zip |
src: add new error apis to prevent memory leaks
This PR creates two new externally-facing APIs, uv_err_name_r() and
uv_strerror_r().
In keeping with the precedent set by POSIX, the *_r() suffix of these
two new methods indicate that the caller does the memory management and
passes in the memory that the output will be stored in, which provides
an alternative for the two existent methods (uv_err_name() and
uv_strerror()), which, when called with an unknown error code, leak a
few bytes of memory.
PR-URL: https://github.com/libuv/libuv/pull/1898
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno santiago.gimeno@gmail.com
Diffstat (limited to 'test/test-error.c')
-rw-r--r-- | test/test-error.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/test-error.c b/test/test-error.c index a2d559a4..7f44f4a1 100644 --- a/test/test-error.c +++ b/test/test-error.c @@ -37,6 +37,8 @@ * See https://github.com/joyent/libuv/issues/210 */ TEST_IMPL(error_message) { + char buf[32]; + /* Cop out. Can't do proper checks on systems with * i18n-ized error messages... */ @@ -49,6 +51,10 @@ TEST_IMPL(error_message) { ASSERT(strcmp(uv_strerror(1337), "Unknown error") == 0); ASSERT(strcmp(uv_strerror(-1337), "Unknown error") == 0); + ASSERT(strstr(uv_strerror_r(UV_EINVAL, buf, sizeof(buf)), "Success") == NULL); + ASSERT(strstr(uv_strerror_r(1337, buf, sizeof(buf)), "1337") != NULL); + ASSERT(strstr(uv_strerror_r(-1337, buf, sizeof(buf)), "-1337") != NULL); + return 0; } |