---
name: "TSMBufferCreate"
section: "3ts"
platform: "linux"
package: "trafficserver-dev"
version: "9.2.5+ds-0+deb12u4"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/TSMBufferCreate"
---

# TSMBufferCreate(3ts)

traffic Server marshall buffer API

## NAME

TSMBufferCreate - traffic Server marshall buffer API

## SYNOPSIS

```
#include <ts/ts.h>
```

- ***TSMBuffer* TSMBufferCreate(void)**

  - ***TSReturnCode* TSMBufferDestroy(*TSMBuffer* bufp)**

  - ***TSReturnCode* TSHandleMLocRelease(*TSMBuffer* bufp, *TSMLoc* parent, *TSMLoc* mloc)**

  ## DESCRIPTION

The marshal buffer or *TSMBuffer* is a heap data structure that stores parsed URLs, MIME headers and HTTP headers. You can allocate new objects out of marshal buffers, and change the values within the marshal buffer. Whenever you manipulate an object, you require the handle to the object (*TSMLoc*) and the marshal buffer containing the object (*TSMBuffer*).

Any marshal buffer fetched by transaction getters will be used by other parts of the system. Be careful not to destroy these shared, transaction marshal buffers.

*TSMBufferCreate()* creates a new marshal buffer and initializes the reference count. *TSMBufferDestroy()* Ignores the reference count and destroys the marshal buffer bufp. The internal data buffer associated with the marshal buffer is also destroyed if the marshal buffer allocated it.

*TSHandleMLocRelease()* Releases the *TSMLoc* mloc created from the *TSMLoc* parent. If a *TSMLoc* is obtained from a transaction, it does not have a parent *TSMLoc*. Use the the constant *TS\_NULL\_MLOC* as its parent.

## RETURN VALUES

*TSMBufferDestroy()* and *TSHandleMLocRelease()* return *TS\_SUCCESS* on success, or *TS\_ERROR* on failure. *TSMBufferCreate()* returns the new *TSMBuffer*.

## EXAMPLES

```
#include <ts/ts.h>
static void
copyResponseMimeHdr (TSCont pCont, TSHttpTxn pTxn)
{
    TSMBuffer respHdrBuf, tmpBuf;
    TSMLoc respHttpHdrLoc, tmpMimeHdrLoc;
    if (!TSHttpTxnClientRespGet(pTxn, &respHdrBuf, &respHttpHdrLoc)) {
        TSError("couldn't retrieve client response header0);
        TSHandleMLocRelease(respHdrBuf, TS_NULL_MLOC, respHttpHdrLoc);
        goto done;
    }
    tmpBuf = TSMBufferCreate();
    tmpMimeHdrLoc = TSMimeHdrCreate(tmpBuf);
    TSMimeHdrCopy(tmpBuf, tmpMimeHdrLoc, respHdrBuf, respHttpHdrLoc);
    TSHandleMLocRelease(tmpBuf, TS_NULL_MLOC, tmpMimeHdrLoc);
    TSHandleMLocRelease(respHdrBuf, TS_NULL_MLOC, respHttpHdrLoc);
    TSMBufferDestroy(tmpBuf);
done:
    TSHttpTxnReenable(pTxn, TS_EVENT_HTTP_CONTINUE);
}
```

## SEE ALSO

**[TSAPI(3ts)](/TSAPI/3ts.md)**

## COPYRIGHT

2026, dev@trafficserver.apache.org
