From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Fri, 7 Oct 2022 15:17:42 +0000 (+0100) Subject: Start using libgcrypt again, as there appears to be a memory leak in openssl when... X-Git-Tag: 4.1-rc2~1^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cc97d5099a95ebe6797367127b8b994a9dac30a;p=thirdparty%2Fshairport-sync.git Start using libgcrypt again, as there appears to be a memory leak in openssl when used in the pair_ap library. --- diff --git a/Makefile.am b/Makefile.am index 1dc654cc..bc6710d8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = man ARFLAGS = cr -lib_pair_ap_a_CFLAGS = -Wall -g -DCONFIG_OPENSSL -pthread +lib_pair_ap_a_CFLAGS = -Wall -g -DCONFIG_GCRYPT -pthread lib_tinyhttp_a_CFLAGS = -pthread lib_dbus_interface_a_CFLAGS = -pthread lib_mpris_interface_a_CFLAGS = -pthread diff --git a/configure.ac b/configure.ac index fd233952..b0f53cd9 100644 --- a/configure.ac +++ b/configure.ac @@ -412,6 +412,11 @@ if test "x$with_airplay_2" = "xyes" ; then ]) ]) PKG_CHECK_MODULES([libsodium], [libsodium],[CFLAGS="${libsodium_CFLAGS} ${CFLAGS}" LIBS="${libsodium_LIBS} ${LIBS}"],[AC_MSG_ERROR(AirPlay 2 support requires libsodium -- libsodium-dev suggested)]) + PKG_CHECK_MODULES([libgcrypt], [libgcrypt],[CFLAGS="${libgcrypt_CFLAGS} ${CFLAGS}" LIBS="${libgcrypt_LIBS} ${LIBS}"],[ + AC_CHECK_LIB([gcrypt], [gcry_control], [], [ + AC_MSG_ERROR([Airplay 2 support requires libgcrypt -- libgcrypt-dev suggested]) + ]) + ]) PKG_CHECK_MODULES([libavutil], [libavutil],[CFLAGS="${libavutil_CFLAGS} ${CFLAGS}" LIBS="${libavutil_LIBS} ${LIBS}"],[ AC_MSG_ERROR(AirPlay 2 support requires libavutil -- libavutil-dev suggested)]) PKG_CHECK_MODULES([libavcodec], [libavcodec],[CFLAGS="${libavcodec_CFLAGS} ${CFLAGS}" LIBS="${libavcodec_LIBS} ${LIBS}"],[ diff --git a/shairport.c b/shairport.c index aec61bc7..9d1657f0 100644 --- a/shairport.c +++ b/shairport.c @@ -45,6 +45,7 @@ #ifdef CONFIG_AIRPLAY_2 #include "ptp-utilities.h" +#include #include #include #include @@ -2103,6 +2104,28 @@ int main(int argc, char **argv) { debug(1, "libsodium initialised."); } + // this code is based on + // https://www.gnupg.org/documentation/manuals/gcrypt/Initializing-the-library.html + + /* Version check should be the very first call because it + makes sure that important subsystems are initialized. + #define NEED_LIBGCRYPT_VERSION to the minimum required version. */ + +#define NEED_LIBGCRYPT_VERSION "1.5.4" + + if (!gcry_check_version(NEED_LIBGCRYPT_VERSION)) { + die("libgcrypt is too old (need %s, have %s).", NEED_LIBGCRYPT_VERSION, + gcry_check_version(NULL)); + } + + /* Disable secure memory. */ + gcry_control(GCRYCTL_DISABLE_SECMEM, 0); + + /* ... If required, other initialization goes here. */ + + /* Tell Libgcrypt that initialization has completed. */ + gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); + #endif /* Mess around with the latency options */