diff --git a/include/tscore/ink_memory.h b/include/tscore/ink_memory.h index d02411139ea..713cb02e3f6 100644 --- a/include/tscore/ink_memory.h +++ b/include/tscore/ink_memory.h @@ -141,6 +141,8 @@ char *_xstrdup(const char *str, int length, const char *path); #ifdef __cplusplus +#include + // this is to help with migration to a std::string issue with older code that // expects char* being copied. As more code moves to std::string, this can be // removed to avoid these extra copies. @@ -618,4 +620,15 @@ path_join(ats_scoped_str const &lhs, ats_scoped_str const &rhs) return x.release(); } + +struct ats_unique_buf_deleter { + void + operator()(uint8_t *p) + { + ats_free(p); + } +}; +using ats_unique_buf = std::unique_ptr; +ats_unique_buf ats_unique_malloc(size_t size); + #endif /* __cplusplus */ diff --git a/src/tscore/ink_memory.cc b/src/tscore/ink_memory.cc index aca92b80142..b34a726773e 100644 --- a/src/tscore/ink_memory.cc +++ b/src/tscore/ink_memory.cc @@ -161,6 +161,12 @@ ats_mallopt(int param ATS_UNUSED, int value ATS_UNUSED) return 0; } +ats_unique_buf +ats_unique_malloc(size_t size) +{ + return ats_unique_buf(static_cast(ats_malloc(size))); +} + int ats_msync(caddr_t addr, size_t len, caddr_t end, int flags) {