---
name: "dwarf_finish"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/dwarf_finish"
---

# dwarf\_finish(3)

free resources associated with a debug descriptor

## NAME

**dwarf\_finish**, **dwarf\_object\_finish** – free resources associated with a debug descriptor

## LIBRARY

library “libdwarf”

## SYNOPSIS

**#include \<libdwarf.h\>**

*int*\

**dwarf\_finish**(*Dwarf\_Debug dbg*, *Dwarf\_Error \*err*);

*int*\

**dwarf\_object\_finish**(*Dwarf\_Debug dbg*, *Dwarf\_Error \*err*);

## DESCRIPTION

The **dwarf\_finish**() and **dwarf\_object\_finish**() functions are used to release the resources associated with a debug descriptor allocated by a prior call to [dwarf\_init(3)](/dwarf_init/3.md) and [dwarf\_object\_init(3)](/dwarf_object_init/3.md) respectively.

Argument *dbg* denotes a valid *Dwarf\_Debug* instance. Argument *err* will be used to record error information in case of an error.

After a call to **dwarf\_finish**() or **dwarf\_object\_finish**(), the argument *dbg* will be invalid and should not be used further.

For *Dwarf\_Debug* descriptors opened using [dwarf\_init(3)](/dwarf_init/3.md), the application would need to explicitly release the *Elf* instance associated with the descriptor by first retrieving the instance using [dwarf\_get\_elf(3)](/dwarf_get_elf/3.md) and closing it using [elf\_end(3)](/elf_end/3.md).

## RETURN VALUES

These functions return DW\_DLV\_OK if successful. In case of an error, the functions return DW\_DLV\_ERROR and record additional information in argument *err*.

## EXAMPLES

To deallocate a *Dwarf\_Debug* instance allocated using [dwarf\_elf\_init(3)](/dwarf_elf_init/3.md) use:

```
Dwarf_Debug dbg;
Dwarf_Error de;
if (dwarf_finish(dbg, &de) != DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_finish: %s", dwarf_errmsg(de));
```

To deallocate a *Dwarf\_Debug* instance allocated using [dwarf\_object\_init(3)](/dwarf_object_init/3.md) use:

```
Dwarf_Debug dbg;
Dwarf_Error de;
if (dwarf_object_finish(dbg, &de) != DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_object_finish: %s",
	    dwarf_errmsg(de));
```

To deallocate a *Dwarf\_Debug* instance allocated using [dwarf\_init(3)](/dwarf_init/3.md) use:

```
Dwarf_Debug dbg;
Dward_Error de;
Elf *e;
if (dwarf_get_elf(dbg, &e, &de) != DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_get_elf: %s", dwarf_errmsg(&de));
if (dwarf_finish(dbg, &de) != DW_DLV_OK)
	errx(EXIT_FAILURE, "dwarf_finish: %s", dwarf_errmsg(de));
(void) elf_end(e);
```

## SEE ALSO

[dwarf\_elf\_init(3)](/dwarf_elf_init/3.md), [dwarf\_get\_elf(3)](/dwarf_get_elf/3.md), [dwarf\_init(3)](/dwarf_init/3.md), [dwarf\_object\_init(3)](/dwarf_object_init/3.md), [elf\_end(3)](/elf_end/3.md)
