erickguan / ffi-icu

FFI wrappers for ICU. MRI extension with the dynamic C library.
https://github.com/erickguan/ffi-icu
MIT License
35 stars 22 forks source link

Use the correct function to delete udatpg objects #52

Closed KJTsanaktsidis closed 2 years ago

KJTsanaktsidis commented 2 years ago

The skeleton generator is currently using udat_close to delete objects created with udatpg_open; it should be using udatpg_close instead.

The C-side implementation of udat_close calls straight into the C++ delete operator:

U_CAPI void U_EXPORT2
udat_close(UDateFormat* format)
{
    delete (DateFormat*)format;
}

The destructor on the DateFormat class is virtual, so i'm frankly astonished this isn't just chasing and calling a pointer to nowhere. I guess we got "lucky" and DateFormat and DateTimePatternGenerator have a similar enough layout by chance that this works. However it's entirely at the whim of the compiler as to whether this keeps working or not, so we should fix it and call the correct cleanup function.