Welcome! Log In Create A New Profile

Advanced

[njs] Fixed realloc() failure handling.

Dmitry Volyntsev
September 26, 2017 07:22AM
details: http://hg.nginx.org/njs/rev/f6b9efd315c5
branches:
changeset: 409:f6b9efd315c5
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Sep 26 14:19:49 2017 +0300
description:
Fixed realloc() failure handling.

According to POSIX, if realloc() fails to allocate a new chunk of memory
it returns NULL and does not free the original pointer.

Using a separate pointer in order to preserve the original one.

diffstat:

njs/njs.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)

diffs (30 lines):

diff -r 616370bb1386 -r f6b9efd315c5 njs/njs.c
--- a/njs/njs.c Fri Sep 01 18:51:20 2017 +0300
+++ b/njs/njs.c Tue Sep 26 14:19:49 2017 +0300
@@ -300,7 +300,7 @@ njs_process_file(njs_opts_t *opts, njs_v
{
int fd;
char *file;
- u_char buf[4096], *p, *end;
+ u_char buf[4096], *p, *end, *start;
size_t size;
ssize_t n;
njs_vm_t *vm;
@@ -364,13 +364,15 @@ njs_process_file(njs_opts_t *opts, njs_v
if (p + n > end) {
size *= 2;

- script.start = realloc(script.start, size);
- if (script.start == NULL) {
+ start = realloc(script.start, size);
+ if (start == NULL) {
fprintf(stderr, "alloc failed while reading '%s'\n", file);
ret = NXT_ERROR;
goto done;
}

+ script.start = start;
+
p = script.start + script.length;
end = script.start + size;
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed realloc() failure handling.

Dmitry Volyntsev 460 September 26, 2017 07:22AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 201
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready