From: Mike Brady Date: Mon, 28 Aug 2017 20:33:29 +0000 (+0100) Subject: Fix an issue where it would terminate if it could not allocate an excessively large... X-Git-Tag: 3.2d5~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f283f95dcbef24e2a91537e91ed3fc9d8171e482;p=thirdparty%2Fshairport-sync.git Fix an issue where it would terminate if it could not allocate an excessively large buffer. --- diff --git a/player.c b/player.c index 4a563834..fe3bb350 100644 --- a/player.c +++ b/player.c @@ -1829,11 +1829,15 @@ static void *player_thread_func(void *arg) { // debug(1, "Large positive sync error: %lld. Dropping the frame.", sync_error); } else if ((sync_error < 0) && ((-sync_error) > filler_length)) { // debug(1, "Large negative sync error: %lld. Inserting silence.", sync_error); - char *long_silence = malloc(conn->output_bytes_per_frame * (-sync_error)); + size_t silence_length = -sync_error; + if (silence_length>(filler_length*5)) + silence_length = filler_length*5; + + char *long_silence = malloc(conn->output_bytes_per_frame * silence_length); if (long_silence == NULL) - die("Failed to allocate memory for a long_silence buffer."); - memset(long_silence, 0, conn->output_bytes_per_frame * (-sync_error)); - config.output->play((short *)long_silence, (-sync_error)); + die("Failed to allocate memory for a long_silence buffer of %d frames.",silence_length); + memset(long_silence, 0, conn->output_bytes_per_frame * silence_length); + config.output->play((short *)long_silence, silence_length); free(long_silence); } } else {