Bug 165025 - LibreOfficeKit crashes with SIGSEGV during cleanup in LocaleDataWrapper destructor when destroying a LibreOffice instance.
Summary: LibreOfficeKit crashes with SIGSEGV during cleanup in LocaleDataWrapper destr...
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
24.8.4.2 release
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: LibreOfficeKit
  Show dependency treegraph
 
Reported: 2025-02-03 23:45 UTC by pinformatique
Modified: 2025-09-21 10:45 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
report (2.95 KB, text/plain)
2025-02-03 23:47 UTC, pinformatique
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pinformatique 2025-02-03 23:45:39 UTC
Description:
LibreOfficeKit crashes with a segmentation fault (SIGSEGV) during the cleanup process when a LibreOffice instance is destroyed. This occurs specifically within the destructor of the LocaleDataWrapper class. The crash happens after all document operations (loading, saving) are completed successfully, but before the program terminates. This issue affects applications integrating LibreOfficeKit, particularly those that create and destroy instances frequently. The problem appears to be related to locale handling during the shutdown sequence.



Steps to Reproduce:
1.Create a C++ program using LibreOfficeKit that initializes a LibreOffice instance, loads a document, saves it, and then destroys both the document and LibreOffice instance. Use the provided code as a template:

#include <LibreOfficeKit/LibreOfficeKit.h>
#include <LibreOfficeKit/LibreOfficeKitInit.h>
#include <iostream>
#include <fstream>

int main() {
    LibreOfficeKit* lok = lok_init("/usr/lib/libreoffice/program");
    if (!lok) {
        return 1;
    }

    // Create and load a test document
    std::ofstream test_doc("test.odt");
    test_doc << "Test document";
    test_doc.close();

    LibreOfficeKitDocument* doc = lok->pClass->documentLoad(lok, "test.odt");
    if (doc) {
        doc->pClass->saveAs(doc, "test_save.odt", "odt", nullptr);
        doc->pClass->destroy(doc);
    }

    lok->pClass->destroy(lok);
    return 0;
}


2.Compile the program using the command:

g++ -std=c++17 test.cpp -o test $(pkg-config --cflags --libs libreofficekit)


3.Run the compiled program:

./test

Actual Results:
The program crashes with a segmentation fault (SIGSEGV) during the cleanup process after all document operations are completed. The stack trace points to a crash within the LocaleDataWrapper destructor. The following error message is seen:

Fatal exception: Signal 11
Stack:
#0 /usr/lib/libreoffice/program/libuno_sal.so.3(_ZN3sal13backtrace_getEj+0x30)
#1 /usr/lib/libreoffice/program/libuno_sal.so.3(+0x41ce5)
#2 /usr/lib/libreoffice/program/libuno_sal.so.3(+0x41f2a)
#3 /lib/x86_64-linux-gnu/libc.so.6(+0x42520)
#4 /usr/lib/libreoffice/program/libuno_sal.so.3(rtl_uString_release+0x4)
#5 /usr/lib/libreoffice/program/libmergedlo.so(_ZN17LocaleDataWrapperD1Ev+0x17)

Expected Results:
The program should terminate cleanly without any crashes after all document operations are finished.




Reproducible: Always


User Profile Reset: No

Additional Info:
OS: Ubuntu 22.04 LTS (via WSL2)

LibreOffice Version: 24.8.4.2

Build ID: 480(Build:2)

Compiler: GCC

C++ Standard: C++17

This issue was discovered while developing a C++ bridge for LibreOffice integration

The crash is reproducible with both simple and complex documents

The issue persists across multiple program runs

Workarounds are currently in place (instance pooling, signal catching, try/catch blocks around destroy), but a proper fix is needed.
Comment 1 pinformatique 2025-02-03 23:47:28 UTC
Created attachment 198950 [details]
report