Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix memory leak in debugerrno
  • Loading branch information
Fabian Mauchle committed May 19, 2021
1 parent e94dcce commit 70952d3
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions debug.c
Expand Up @@ -201,8 +201,8 @@ void debug_logit(uint8_t level, const char *format, va_list ap) {
vsyslog(priority, format, ap);
} else {
if (debug_timestamp && (timebuf = malloc(26 + 1))) {
gettimeofday(&now, NULL);
ctime_r(&now.tv_sec, timebuf);
gettimeofday(&now, NULL);
ctime_r(&now.tv_sec, timebuf);
/*ctime_r writes exactly 24 bytes + "\n\0" */
strncpy(timebuf+24,": ", 3);
}
Expand All @@ -211,8 +211,8 @@ void debug_logit(uint8_t level, const char *format, va_list ap) {
if (tmp2) {
snprintf(tmp2, malloc_size, "%s%s\n", timebuf ? timebuf : "", format);
format = tmp2;
}
vfprintf(debug_file, format, ap);
}
vfprintf(debug_file, format, ap);
}
free(tmp);
free(tmp2);
Expand Down Expand Up @@ -240,18 +240,20 @@ void debugx(int status, uint8_t level, char *format, ...) {

void debugerrno(int err, uint8_t level, char *format, ...) {
if (level >= debug_level) {
va_list ap;
size_t len = strlen(format);
char *tmp = malloc(len + 1024 + 2);
assert(tmp);
strcpy(tmp, format);
tmp[len++] = ':';
tmp[len++] = ' ';
if (strerror_r(err, tmp + len, 1024))
tmp = format;
va_start(ap, format);
debug_logit(level, tmp, ap);
va_end(ap);
va_list ap;
size_t len = strlen(format);
char *tmp = malloc(len + 1024 + 2);
assert(tmp);
strcpy(tmp, format);
tmp[len++] = ':';
tmp[len++] = ' ';
va_start(ap, format);
if (strerror_r(err, tmp + len, 1024))
debug_logit(level, format, ap);
else
debug_logit(level, tmp, ap);
va_end(ap);
free(tmp);
}
}

Expand Down

0 comments on commit 70952d3

Please sign in to comment.