From 8fa3dd3f224a12a60dfd23780afe658e69dcdc4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Tue, 26 Jan 2021 10:06:17 +0100 Subject: [PATCH] Defined ntfs_realloc() and ntfs_free() Currently memory allocations are done through ntfs_malloc() and ntfs_calloc(), but releases are done through free(3). Defining an ntfs_free() relay facilitates the debugging of memory leaks in plugins. --- include/ntfs-3g/misc.h | 2 ++ libntfs-3g/misc.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/ntfs-3g/misc.h b/include/ntfs-3g/misc.h index a03e964e..c5568b39 100644 --- a/include/ntfs-3g/misc.h +++ b/include/ntfs-3g/misc.h @@ -25,6 +25,8 @@ void *ntfs_calloc(size_t size); void *ntfs_malloc(size_t size); +void *ntfs_realloc(void *ptr, size_t size); +void ntfs_free(void *ptr); #endif /* _NTFS_MISC_H_ */ diff --git a/libntfs-3g/misc.c b/libntfs-3g/misc.c index b2e17cbf..03fb592a 100644 --- a/libntfs-3g/misc.c +++ b/libntfs-3g/misc.c @@ -59,3 +59,19 @@ void *ntfs_malloc(size_t size) ntfs_log_perror("Failed to malloc %lld bytes", (long long)size); return p; } + +void *ntfs_realloc(void *ptr, size_t size) +{ + void *p; + + p = realloc(ptr, size); + if (!p) + ntfs_log_perror("Failed to realloc %lld bytes", + (long long)size); + return p; +} + +void ntfs_free(void *p) +{ + free(p); +}