mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-24 06:05:56 -05:00
[mxml] Simplify mxml workarounds
This commit is contained in:
parent
5ad5f85cc4
commit
19358dc869
11
configure.ac
11
configure.ac
@ -117,17 +117,8 @@ FORK_MODULES_CHECK([FORKED], [CONFUSE], [libconfuse >= 3.0], [cfg_init], [confus
|
||||
FORK_MODULES_CHECK([FORKED], [MINIXML], [mxml],
|
||||
[mxmlNewElement], [mxml.h],
|
||||
[
|
||||
dnl See mxml-compat.h
|
||||
AC_CHECK_FUNCS([mxmlGetOpaque] [mxmlGetText] [mxmlGetType] [mxmlGetFirstChild])
|
||||
dnl check for versions 2.10 and earlier which have a serious memleak
|
||||
PKG_CHECK_EXISTS([mxml < 2.11],
|
||||
[AC_DEFINE([HAVE_MXML_V211LT], 1,
|
||||
[Define to 1 if you have mxml < 2.11)])]
|
||||
)
|
||||
dnl Debian amd64 mxml 2.12 has a mxmlNewTextf that segfaults
|
||||
PKG_CHECK_EXISTS([mxml = 2.12],
|
||||
[AC_DEFINE([HAVE_MXML_V212], 1,
|
||||
[Define to 1 if you have mxml = 2.12)])]
|
||||
)
|
||||
])
|
||||
|
||||
FORK_MODULES_CHECK([COMMON], [SQLITE3], [sqlite3 >= 3.5.0],
|
||||
|
@ -1,15 +1,15 @@
|
||||
#ifndef __MXML_COMPAT_H__
|
||||
#define __MXML_COMPAT_H__
|
||||
|
||||
#include <mxml.h>
|
||||
|
||||
// mxml 2.10 has a memory leak in mxmlDelete, see https://github.com/michaelrsweet/mxml/issues/183
|
||||
// - and since this is the version in Ubuntu 18.04 LTS and Raspian Stretch, we
|
||||
// fix it by including a fixed mxmlDelete here. It should be removed once the
|
||||
// major distros no longer have 2.10. The below code is msweet's fixed mxml.
|
||||
#if defined(HAVE_MXML_211LT)
|
||||
// Trick to undefine mxml.h's mxmlDelete
|
||||
#define mxmlDelete mxmlDelete_memleak
|
||||
# include <mxml.h>
|
||||
#undef mxmlDelete
|
||||
#if (MXML_MAJOR_VERSION == 2) && (MXML_MINOR_VERSION <= 10)
|
||||
|
||||
#define mxmlDelete compat_mxmlDelete
|
||||
|
||||
static void
|
||||
compat_mxml_free(mxml_node_t *node)
|
||||
@ -59,8 +59,8 @@ compat_mxml_free(mxml_node_t *node)
|
||||
free(node);
|
||||
}
|
||||
|
||||
static void
|
||||
mxmlDelete(mxml_node_t *node)
|
||||
__attribute__((unused)) static void
|
||||
compat_mxmlDelete(mxml_node_t *node)
|
||||
{
|
||||
mxml_node_t *current,
|
||||
*next;
|
||||
@ -87,30 +87,38 @@ mxmlDelete(mxml_node_t *node)
|
||||
|
||||
compat_mxml_free(node);
|
||||
}
|
||||
#elif defined(HAVE_MXML_212)
|
||||
// Trick to undefine mxml.h's mxmlNewTextf
|
||||
#define mxmlNewTextf mxmlNewTextf_segfault
|
||||
# include <mxml.h>
|
||||
#undef mxmlNewTextf
|
||||
#endif
|
||||
|
||||
static mxml_node_t *
|
||||
mxmlNewTextf(mxml_node_t *parent, int whitespace, const char *format, ...)
|
||||
// Debian 10.x amd64 w/mxml 2.12 has a mxmlNewTextf that causes segfault when
|
||||
// mxmlSaveString or mxmlSaveAllocString is called,
|
||||
// ref https://github.com/ejurgensen/forked-daapd/issues/938
|
||||
#if (MXML_MAJOR_VERSION == 2) && (MXML_MINOR_VERSION == 12)
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define mxmlNewTextf compat_mxmlNewTextf
|
||||
|
||||
__attribute__((unused)) static mxml_node_t *
|
||||
compat_mxmlNewTextf(mxml_node_t *parent, int whitespace, const char *format, ...)
|
||||
{
|
||||
char *s = NULL;
|
||||
va_list va;
|
||||
mxml_node_t *node;
|
||||
int ret;
|
||||
|
||||
va_start(va, format);
|
||||
vasprintf(&s, format, va);
|
||||
ret = vasprintf(&s, format, va);
|
||||
va_end(va);
|
||||
|
||||
if (ret < 0)
|
||||
return NULL;
|
||||
|
||||
node = mxmlNewText(parent, whitespace, s);
|
||||
|
||||
free(s);
|
||||
|
||||
return node;
|
||||
}
|
||||
#else
|
||||
# include <mxml.h>
|
||||
#endif
|
||||
|
||||
/* For compability with mxml 2.6 */
|
||||
|
Loading…
Reference in New Issue
Block a user