if (logsrv->maxlen > global.max_syslog_len) {
global.max_syslog_len = logsrv->maxlen;
- logheader = realloc(logheader, global.max_syslog_len + 1);
- logheader_rfc5424 = realloc(logheader_rfc5424, global.max_syslog_len + 1);
- logline = realloc(logline, global.max_syslog_len + 1);
- logline_rfc5424 = realloc(logline_rfc5424, global.max_syslog_len + 1);
+ logheader = my_realloc2(logheader, global.max_syslog_len + 1);
+ logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
+ logline = my_realloc2(logline, global.max_syslog_len + 1);
+ logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
}
/* after the length, a format may be specified */
if (logsrv->maxlen > global.max_syslog_len) {
global.max_syslog_len = logsrv->maxlen;
- logheader = realloc(logheader, global.max_syslog_len + 1);
- logheader_rfc5424 = realloc(logheader_rfc5424, global.max_syslog_len + 1);
- logline = realloc(logline, global.max_syslog_len + 1);
- logline_rfc5424 = realloc(logline_rfc5424, global.max_syslog_len + 1);
+ logheader = my_realloc2(logheader, global.max_syslog_len + 1);
+ logheader_rfc5424 = my_realloc2(logheader_rfc5424, global.max_syslog_len + 1);
+ logline = my_realloc2(logline, global.max_syslog_len + 1);
+ logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
}
/* after the length, a format may be specified */
#include <common/config.h>
#include <common/chunk.h>
+#include <common/standard.h>
/* trash chunks used for various conversions */
static struct chunk *trash_chunk;
int alloc_trash_buffers(int bufsize)
{
trash_size = bufsize;
- trash_buf1 = (char *)realloc(trash_buf1, bufsize);
- trash_buf2 = (char *)realloc(trash_buf2, bufsize);
+ trash_buf1 = (char *)my_realloc2(trash_buf1, bufsize);
+ trash_buf2 = (char *)my_realloc2(trash_buf2, bufsize);
return trash_buf1 && trash_buf2;
}
}
allocated = needed + 1;
- ret = realloc(ret, allocated);
+ ret = my_realloc2(ret, allocated);
} while (ret);
if (needed < 0) {
val_len = value ? strlen(value) : 0;
}
- out = realloc(out, out_len + (txt_end - txt_beg) + val_len + 1);
+ out = my_realloc2(out, out_len + (txt_end - txt_beg) + val_len + 1);
if (txt_end > txt_beg) {
memcpy(out + out_len, txt_beg, txt_end - txt_beg);
out_len += txt_end - txt_beg;
static char *register_name(const char *name, int len, enum vars_scope *scope, char **err)
{
int i;
+ char **var_names2;
const char *tmp;
/* Check length. */
if (strncmp(var_names[i], name, len) == 0)
return var_names[i];
- /* Store variable name. */
- var_names_nb++;
- var_names = realloc(var_names, var_names_nb * sizeof(*var_names));
- if (!var_names) {
+ /* Store variable name. If realloc fails, var_names remains valid */
+ var_names2 = realloc(var_names, (var_names_nb + 1) * sizeof(*var_names));
+ if (!var_names2) {
memprintf(err, "out of memory error");
return NULL;
}
+ var_names_nb++;
+ var_names = var_names2;
var_names[var_names_nb - 1] = malloc(len + 1);
if (!var_names[var_names_nb - 1]) {
memprintf(err, "out of memory error");