Module: kamailio Branch: master Commit: 4a71d3c9e6a4f92ef33ce8e62372b2c4dba62a56 URL: https://github.com/kamailio/kamailio/commit/4a71d3c9e6a4f92ef33ce8e62372b2c4...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2025-02-12T17:48:42+01:00
ctl: free rpc struct in case of error
---
Modified: src/modules/ctl/binrpc_run.c
---
Diff: https://github.com/kamailio/kamailio/commit/4a71d3c9e6a4f92ef33ce8e62372b2c4... Patch: https://github.com/kamailio/kamailio/commit/4a71d3c9e6a4f92ef33ce8e62372b2c4...
---
diff --git a/src/modules/ctl/binrpc_run.c b/src/modules/ctl/binrpc_run.c index 1a9eb27bd79..cb1220b5c87 100644 --- a/src/modules/ctl/binrpc_run.c +++ b/src/modules/ctl/binrpc_run.c @@ -1027,7 +1027,7 @@ static int rpc_add(struct binrpc_ctx *ctx, char *fmt, ...) int err; str st; str *sp; - struct rpc_struct_l *rs; + struct rpc_struct_l *rs = NULL; str null_value = str_init("<null string>"); double d;
@@ -1071,12 +1071,14 @@ static int rpc_add(struct binrpc_ctx *ctx, char *fmt, ...) if(err < 0) goto error_add; rs = new_rpc_struct(); - if(rs == 0) + if(rs == NULL) goto error_mem; rs->offset = binrpc_pkt_len(&ctx->out.pkt); err = binrpc_end_struct(&ctx->out.pkt); - if(err < 0) + if(err < 0) { + ctl_free(rs); goto error_add; + } clist_append(&ctx->out.structs, rs, next, prev); *(va_arg(ap, void **)) = rs; break; @@ -1182,7 +1184,7 @@ static int rpc_struct_add(struct rpc_struct_l *s, char *fmt, ...) va_list ap; int err; struct binrpc_val avp; - struct rpc_struct_l *rs; + struct rpc_struct_l *rs = NULL; str *sp; str null_value = str_init("<null string>");
@@ -1228,7 +1230,7 @@ static int rpc_struct_add(struct rpc_struct_l *s, char *fmt, ...) goto error_add; } rs = new_rpc_struct(); - if(rs == 0) { + if(rs == NULL) { LM_ERR("not enough memory (%c)\n", *fmt); goto error_mem; } @@ -1236,6 +1238,7 @@ static int rpc_struct_add(struct rpc_struct_l *s, char *fmt, ...) err = binrpc_end_struct(&s->pkt); if(err < 0) { LM_ERR("failed to end struct (%c)\n", *fmt); + ctl_free(rs); goto error_add; } clist_append(&s->substructs, rs, next, prev); @@ -1291,8 +1294,8 @@ static int rpc_array_add(struct rpc_struct_l *s, char *fmt, ...) va_list ap; int err; str st; - str *sp; - struct rpc_struct_l *rs; + str *sp = NULL; + struct rpc_struct_l *rs = NULL; str null_value = str_init("<null string>"); double d;
@@ -1336,12 +1339,14 @@ static int rpc_array_add(struct rpc_struct_l *s, char *fmt, ...) if(err < 0) goto error_add; rs = new_rpc_struct(); - if(rs == 0) + if(rs == NULL) goto error_mem; rs->offset = binrpc_pkt_len(&s->pkt); err = binrpc_end_struct(&s->pkt); - if(err < 0) + if(err < 0) { + ctl_free(rs); goto error_add; + } clist_append(&s->substructs, rs, next, prev); *(va_arg(ap, void **)) = rs; break;