TSMALLOC(3ts)

πŸ“¦
version 9.2.5 Β· 4 versions
, in ubuntu noble, ubuntu questing

πŸ’– TSMALLOC β€” the memory glow-up page (3ts) πŸ’–

okay bestie, welcome to TSmalloc, aka the Traffic Server memory allocation API. this is from the Apache Traffic Server fam, and it's genuinely one of those pages you're gonna come back to constantly, so let's get into it 🫢


✨ SYNOPSIS ✨

#include <ts/ts.h>

void *TSmalloc(size_t size)

void *TSrealloc(void *ptr, size_t size)

char *TSstrdup(const char *str)

char *TSstrndup(const char *str, size_t size)

size_t TSstrlcpy(char *dst, const char *src, size_t size)

size_t TSstrlcat(char *dst, const char *src, size_t size)

void TSfree(void *ptr)

🌸 DESCRIPTION 🌸

so Traffic Server hands you a whole lil set of routines for allocating and freeing memory, and honestly? they're the C library routines' cooler cousins. like, TSrealloc() does the exact same vibe as the C library routine realloc. no cap.

but why would you use these instead of just... the normal ones? two reasons, and both are valid:

  • Portability β€” the Traffic Server API routines behave the same on all of Traffic Server's supported platforms. for example, realloc does not accept an argument of NULL on some platforms. so like, rude of them.
  • Tracking β€” the Traffic Server routines actually track the memory allocations by file and line number. and the tracking is very efficient, it's always turned on, and it is genuinely so useful for tracking down memory leaks. main character behavior honestly.

πŸ’… the functions, one by one πŸ’…

  • TSmalloc() β€” returns a pointer to size bytes of memory allocated from the heap. Traffic Server uses TSmalloc() internally for memory allocations. and listen: always use TSfree() to release memory allocated by TSmalloc(); do not use free. i'm serious, don't do it πŸ™ˆ
  • TSstrdup() β€” returns a pointer to a new string that is a duplicate of the string pointed to by str. the memory for the new string is allocated using TSmalloc() and should be freed by a call to TSfree().
  • TSstrndup() β€” returns a pointer to a new string that is a duplicate of the string pointed to by str but is at most size bytes long. the new string will be NUL-terminated. this API is very useful for transforming non NUL-terminated string values returned by APIs such as TSMimeHdrFieldValueStringGet() into NUL-terminated string values. the memory for the new string is allocated using TSmalloc() and should be freed by a call to TSfree(). obsessed with this one fr fr.
  • TSstrlcpy() β€” copies up to size - 1 characters from the NUL-terminated string src to dst, NUL-terminating the result.
  • TSstrlcat() β€” appends the NUL-terminated string src to the end of dst. it will append at most size - strlen(dst) - 1 bytes, NUL-terminating the result.
  • TSfree() β€” releases the memory allocated by TSmalloc() or TSrealloc(). if ptr is NULL, TSfree() does no operation. she's chill like that ✨
πŸŽ€ friendly reminder from your girl: memory allocated by TSmalloc() gets released with TSfree(), not free. this is the whole entire point. periodt.

πŸ” SEE ALSO πŸ”


2026, dev@trafficserver.apache.org


k that's the whole page bestie, you ate πŸ’– go forth and allocate responsibly, and remember: TSfree() for TSmalloc() memory, always, no exceptions, mwah 🫢

this has been TSmalloc(3ts) from the Apache Traffic Server manual β€” version 9.2, dated Feb 12, 2026. iykyk 🌈✨

πŸ“¦ where this page comes from