[mxml] Simplify mxml workarounds

This commit is contained in:
ejurgensen 2020-04-13 21:29:18 +02:00
parent 5ad5f85cc4
commit 19358dc869
2 changed files with 26 additions and 27 deletions

View File

@ -117,17 +117,8 @@ FORK_MODULES_CHECK([FORKED], [CONFUSE], [libconfuse >= 3.0], [cfg_init], [confus
FORK_MODULES_CHECK([FORKED], [MINIXML], [mxml], FORK_MODULES_CHECK([FORKED], [MINIXML], [mxml],
[mxmlNewElement], [mxml.h], [mxmlNewElement], [mxml.h],
[ [
dnl See mxml-compat.h
AC_CHECK_FUNCS([mxmlGetOpaque] [mxmlGetText] [mxmlGetType] [mxmlGetFirstChild]) 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], FORK_MODULES_CHECK([COMMON], [SQLITE3], [sqlite3 >= 3.5.0],

View File

@ -1,15 +1,15 @@
#ifndef __MXML_COMPAT_H__ #ifndef __MXML_COMPAT_H__
#define __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 // 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 // - 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 // 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. // major distros no longer have 2.10. The below code is msweet's fixed mxml.
#if defined(HAVE_MXML_211LT) #if (MXML_MAJOR_VERSION == 2) && (MXML_MINOR_VERSION <= 10)
// Trick to undefine mxml.h's mxmlDelete
#define mxmlDelete mxmlDelete_memleak #define mxmlDelete compat_mxmlDelete
# include <mxml.h>
#undef mxmlDelete
static void static void
compat_mxml_free(mxml_node_t *node) compat_mxml_free(mxml_node_t *node)
@ -59,8 +59,8 @@ compat_mxml_free(mxml_node_t *node)
free(node); free(node);
} }
static void __attribute__((unused)) static void
mxmlDelete(mxml_node_t *node) compat_mxmlDelete(mxml_node_t *node)
{ {
mxml_node_t *current, mxml_node_t *current,
*next; *next;
@ -87,30 +87,38 @@ mxmlDelete(mxml_node_t *node)
compat_mxml_free(node); compat_mxml_free(node);
} }
#elif defined(HAVE_MXML_212) #endif
// Trick to undefine mxml.h's mxmlNewTextf
#define mxmlNewTextf mxmlNewTextf_segfault
# include <mxml.h>
#undef mxmlNewTextf
static mxml_node_t * // Debian 10.x amd64 w/mxml 2.12 has a mxmlNewTextf that causes segfault when
mxmlNewTextf(mxml_node_t *parent, int whitespace, const char *format, ...) // 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; char *s = NULL;
va_list va; va_list va;
mxml_node_t *node;
int ret;
va_start(va, format); va_start(va, format);
vasprintf(&s, format, va); ret = vasprintf(&s, format, va);
va_end(va); va_end(va);
if (ret < 0)
return NULL;
node = mxmlNewText(parent, whitespace, s); node = mxmlNewText(parent, whitespace, s);
free(s); free(s);
return node; return node;
} }
#else
# include <mxml.h>
#endif #endif
/* For compability with mxml 2.6 */ /* For compability with mxml 2.6 */