Module: kamailio Branch: master Commit: 72e0ebcdcbc5ffcd7ea475334437e56b22e143d4 URL: https://github.com/kamailio/kamailio/commit/72e0ebcdcbc5ffcd7ea475334437e56b22e143d4
Author: Daniel-Constantin Mierla <mico...@gmail.com> Committer: Daniel-Constantin Mierla <mico...@gmail.com> Date: 2017-08-07T13:33:46+02:00 ctl: proper handling of realloc failure to avoid leak --- Modified: src/modules/ctl/fifo_server.c --- Diff: https://github.com/kamailio/kamailio/commit/72e0ebcdcbc5ffcd7ea475334437e56b22e143d4.diff Patch: https://github.com/kamailio/kamailio/commit/72e0ebcdcbc5ffcd7ea475334437e56b22e143d4.patch --- diff --git a/src/modules/ctl/fifo_server.c b/src/modules/ctl/fifo_server.c index a84073a802..18122bfcef 100644 --- a/src/modules/ctl/fifo_server.c +++ b/src/modules/ctl/fifo_server.c @@ -1277,6 +1277,7 @@ static int rpc_rpl_printf(rpc_ctx_t* ctx, char* fmt, ...) { int n, buf_size; char* buf; + char* buf0; va_list ap; str s; struct text_chunk* l; @@ -1287,7 +1288,7 @@ static int rpc_rpl_printf(rpc_ctx_t* ctx, char* fmt, ...) ERR("No memory left\n"); return -1; } - + buf_size = RPC_BUF_SIZE; while (1) { /* Try to print in the allocated space. */ @@ -1314,11 +1315,12 @@ static int rpc_rpl_printf(rpc_ctx_t* ctx, char* fmt, ...) } else { /* glibc 2.0 */ buf_size *= 2; /* twice the old size */ } - if ((buf = ctl_realloc(buf, buf_size)) == 0) { + if ((buf0 = ctl_realloc(buf, buf_size)) == 0) { rpc_fault(ctx, 500, "Internal Server Error (No memory left)"); ERR("No memory left\n"); goto err; } + buf = buf0; } return 0; err: _______________________________________________ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev