# HG changeset patch # User Thomas Klausner # Date 1592245983 -7200 # Node ID c48725959e639681bae583f40373bda85f4e7d5f # Parent 3a40bd55ee7407b79387f428195362528eba2c3b rt_ereg: improve memory handling diff -r 3a40bd55ee74 -r c48725959e63 extensions/rt_ereg/rtereg.c --- a/extensions/rt_ereg/rtereg.c Mon Jun 15 20:32:03 2020 +0200 +++ b/extensions/rt_ereg/rtereg.c Mon Jun 15 20:33:03 2020 +0200 @@ -190,8 +190,12 @@ /* Augment the buffer if needed */ if (avp_hdr->avp_value->os.len >= bufsz) { - CHECK_MALLOC_DO( buf = realloc(buf, avp_hdr->avp_value->os.len + 1), + char *newbuf; + CHECK_MALLOC_DO( newbuf = realloc(buf, avp_hdr->avp_value->os.len + 1), { pthread_mutex_unlock(&mtx); return ENOMEM; } ); + /* Update buffer and buffer size */ + buf = newbuf; + bufsz = avp_hdr->avp_value->os.len + 1; } /* Copy the AVP value */ @@ -319,12 +323,11 @@ static int rtereg_init_config(void) { /* Initialize the configuration */ - if ((rtereg_conf=malloc(sizeof(*rtereg_conf))) == NULL) { + if ((rtereg_conf=calloc(sizeof(*rtereg_conf), 1)) == NULL) { LOG_E("[rt_ereg] malloc failured"); return 1; } rtereg_conf_size = 1; - memset(rtereg_conf, 0, sizeof(*rtereg_conf)); /* Parse the configuration file */ CHECK_FCT( rtereg_conf_handle(rt_ereg_config_file) ); @@ -371,6 +374,7 @@ #ifndef HAVE_REG_STARTEND free(buf); buf = NULL; + bufsz = 0; #endif /* HAVE_REG_STARTEND */ if (pthread_rwlock_wrlock(&rte_lock) != 0) {