Skip to content

Commit 5963292

Browse files
committed
refs: document need to free refs in foreach-callback
References passed to the callback function of `git_reference_foreach` are expected to be owned by the callback. As such, they are never being freed by `git_reference_foreach`, but will have to be freed by the caller. This small detail is never mentioned in the function's documentation, though, making it easy to get wrong. Document this to make it discoverable.
1 parent 90f81f9 commit 5963292

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

include/git2/refs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ typedef int (*git_reference_foreach_name_cb)(const char *name, void *payload);
433433
* passed to this method. Returning a non-zero value from the callback
434434
* will terminate the iteration.
435435
*
436+
* Note that the callback function is responsible to call `git_reference_free`
437+
* on each reference passed to it.
438+
*
436439
* @param repo Repository where to find the refs
437440
* @param callback Function which will be called for every listed ref
438441
* @param payload Additional data to pass to the callback

0 commit comments

Comments
 (0)