Skip to content

out BUGFIX export ly_out_memory() - #2647

Open
GeekQAQ wants to merge 1 commit into
CESNET:develfrom
GeekQAQ:out-memory-export
Open

GeekQAQ wants to merge 1 commit into
CESNET:develfrom
GeekQAQ:out-memory-export

Conversation

@GeekQAQ

@GeekQAQ GeekQAQ commented Nov 19, 2026

Copy link
Copy Markdown

ly_out_memory() is declared with LIBYANG_API_DECL in out.h and listed among the output handler functions, but its definition in out.c lacks LIBYANG_API_DEF. The library is compiled with -fvisibility=hidden, so the default shared library does not export it and programs calling it fail to link:

$ nm -D --defined-only libyang.so | grep -E ' ly_out_(memory|fd|file|filepath|clb|clb_arg)$'
0000000000046a30 T ly_out_clb
0000000000046a90 T ly_out_clb_arg
0000000000046b90 T ly_out_fd
0000000000046d60 T ly_out_file
00000000000471b0 T ly_out_filepath
$ cc out_memory.c -lyang
ld: out_memory.c:14: undefined reference to `ly_out_memory'

out_memory.c is any program calling it, e.g.:

#include <stdio.h>
#include <stdlib.h>

#include <libyang/libyang.h>

int
main(void)
{
    struct ly_out *out;
    char *buf1 = NULL, *buf2 = NULL;

    ly_out_new_memory(&buf1, 0, &out);
    ly_print(out, "data");
    ly_out_memory(out, &buf2, 0);
    printf("%s\n", buf1);

    ly_out_free(out, NULL, 1);
    free(buf1);
    return 0;
}

The unit tests build the library objects into the test binaries, so they do not notice.

Fix: add LIBYANG_API_DEF to the definition, as for the other public functions (like #2297 for lyd_new_term_bin()).

Tested on devel f45939c with clang 21 and the default CMake options: ly_out_memory is exported from libyang.so and the program above links and runs; with ENABLE_TESTS=ON and -fsanitize=address,undefined, ctest passes (70 tests).

The definition lacked LIBYANG_API_DEF, so the function declared in
out.h was not exported from the shared library and programs calling it
failed to link.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 21:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants