---
name: "elf_end"
section: "3"
platform: "linux"
package: "libelf"
version: "0.197-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/elf_end"
---

# elf\_end(3)

Release resources associated with an ELF descriptor.

## NAME

elf\_end - Release resources associated with an ELF descriptor.

## SYNOPSIS

```
#include <libelf.h>
int elf_end(Elf *elf);
```

## DESCRIPTION

The **elf\_end** function releases resources associated with an ELF descriptor previously returned by **elf\_begin**. It decrements the ELF descriptor’s internal reference count by one. When this count reaches zero, the resources associated with the descriptor are freed and the descriptor is invalidated.  If *elf* is not an archive member with ELF kind **ELF\_K\_AR**, the internal reference count is increased by one each time *elf* is passed to **elf\_begin** as the *ref* argument.

An ELF descriptor whose reference count reaches zero is invalidated. Further operations on the descriptor will result in undefined behavior.

## PARAMETERS

- *elf*

  The ELF descriptor (may be NULL).

## RETURN VALUE

Return the ELF descriptor's current internal reference count after decrementing. A return value of zero indicates the ELF descriptor is now invalidated.  If *elf* is NULL, then **elf\_end** also returns 0.

## SEE ALSO

[**elf\_begin**(3)](/elf_begin/3.md), [**libelf**(3)](/libelf/3.md), [**elf**(5)](/elf/5.md)

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **elf\_end**() | Thread safety | MT-Safe |

## REPORTING BUGS

Report bugs to \<elfutils-devel@sourceware.org\> or https://sourceware.org/bugzilla/.
