Skip to content

Commit

Permalink
- Fix add reallocarray to alloc stats unit test, and disable
Browse files Browse the repository at this point in the history
  override of strdup in unbound-host, and the result of config
  get option is freed properly.
  • Loading branch information
wcawijngaards committed Oct 10, 2024
1 parent e020143 commit 8b7782e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,9 @@ struct sockaddr_storage;
# define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
# define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
# define strdup(s) unbound_stat_strdup_log(s, __FILE__, __LINE__, __func__)
#ifdef HAVE_REALLOCARRAY
# define reallocarray(p,n,s) unbound_stat_reallocarray_log(p, n, s, __FILE__, __LINE__, __func__)
#endif
void *unbound_stat_malloc(size_t size);
void *unbound_stat_calloc(size_t nmemb, size_t size);
void unbound_stat_free(void *ptr);
Expand All @@ -1596,6 +1599,8 @@ void unbound_stat_free_log(void *ptr, const char* file, int line,
const char* func);
void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
int line, const char* func);
void *unbound_stat_reallocarray_log(void *ptr, size_t nmemb, size_t size,
const char* file, int line, const char* func);
char *unbound_stat_strdup_log(const char *s, const char* file, int line,
const char* func);
#elif defined(UNBOUND_ALLOC_LITE)
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,9 @@ struct sockaddr_storage;
# define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
# define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
# define strdup(s) unbound_stat_strdup_log(s, __FILE__, __LINE__, __func__)
#ifdef HAVE_REALLOCARRAY
# define reallocarray(p,n,s) unbound_stat_reallocarray_log(p, n, s, __FILE__, __LINE__, __func__)
#endif
void *unbound_stat_malloc(size_t size);
void *unbound_stat_calloc(size_t nmemb, size_t size);
void unbound_stat_free(void *ptr);
Expand All @@ -2404,6 +2407,8 @@ void unbound_stat_free_log(void *ptr, const char* file, int line,
const char* func);
void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
int line, const char* func);
void *unbound_stat_reallocarray_log(void *ptr, size_t nmemb, size_t size,
const char* file, int line, const char* func);
char *unbound_stat_strdup_log(const char *s, const char* file, int line,
const char* func);
#elif defined(UNBOUND_ALLOC_LITE)
Expand Down
3 changes: 3 additions & 0 deletions doc/Changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
10 October 2024: Wouter
- Fix cookie_file test sporadic fails for time change during
the test.
- Fix add reallocarray to alloc stats unit test, and disable
override of strdup in unbound-host, and the result of config
get option is freed properly.

9 October 2024: Wouter
- Merge #871: DNS over QUIC. This adds `quic-port: 853` and
Expand Down
6 changes: 6 additions & 0 deletions smallapp/unbound-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#undef calloc
#undef free
#undef realloc
#undef reallocarray
#undef strdup
#endif
#ifdef UNBOUND_ALLOC_LITE
#undef malloc
Expand Down Expand Up @@ -492,7 +494,11 @@ int main(int argc, char* argv[])
if(strcmp(use_syslog, "yes") == 0) /* disable use-syslog */
check_ub_res(ub_ctx_set_option(ctx,
"use-syslog:", "no"));
#ifdef UNBOUND_ALLOC_STATS
unbound_stat_free_log(use_syslog, __FILE__, __LINE__, __func__);
#else
free(use_syslog);
#endif
}
argc -= optind;
argv += optind;
Expand Down
9 changes: 9 additions & 0 deletions util/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,15 @@ void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
return unbound_stat_realloc(ptr, size);
}

/** log to file where alloc was done */
void *unbound_stat_reallocarray_log(void *ptr, size_t nmemb, size_t size,
const char* file, int line, const char* func)
{
log_info("%s:%d %s reallocarray(%p, %u, %u)", file, line, func,
ptr, (unsigned)nmemb, (unsigned)size);
return unbound_stat_realloc(ptr, nmemb*size);
}

/** log to file where strdup was done */
char *unbound_stat_strdup_log(const char *s, const char* file, int line,
const char* func)
Expand Down

0 comments on commit 8b7782e

Please sign in to comment.