---
name: "bson_destroy_with_steal"
section: "3"
platform: "linux"
package: "libbson-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/bson_destroy_with_steal"
---

# bson\_destroy\_with\_steal(3)

## SYNOPSIS

```
uint8_t *
bson_destroy_with_steal (bson_t *bson, bool steal, uint32_t *length);
```

## PARAMETERS

- •

  **bson**: A *bson\_t*.

- •

  **steal**: A bool indicating if the underlying buffer should be stolen.

- •

  **length**: A location for storing the resulting buffer length.

## DESCRIPTION

The *bson\_destroy\_with\_steal()* function shall destroy a *bson\_t* structure but return the underlying buffer instead of freeing it. If steal is false, this is equivalent to calling bson\_destroy(). It is a programming error to call this function on a *bson\_t* that is not a top-level *bson\_t*, such as those initialized with *bson\_append\_document\_begin()*, *bson\_append\_array\_begin()*, and *bson\_writer\_begin()*.

## RETURNS

*bson\_destroy\_with\_steal()* shall return a buffer containing the contents of the *bson\_t* if **steal** is non-zero. This should be freed with *bson\_free()* when no longer in use. **length** will be set to the length of the bson document if non-NULL.

**SEE ALSO:**

```
bson_steal(), a higher-level function that efficiently transfers the contents of one bson_t to another.
```

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
