From 4490a8bbc353ebeb882780ccc1c8755c9df4b602 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Tue, 13 Jun 2017 11:16:04 +0200 Subject: [PATCH] cache sync: don't do memcpy(..., 0, 0) !ctx->buf => ctx->tail - ctx->head == 0 --- src/borg/cache_sync/cache_sync.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/borg/cache_sync/cache_sync.c b/src/borg/cache_sync/cache_sync.c index e4bc653b2..70f568f82 100644 --- a/src/borg/cache_sync/cache_sync.c +++ b/src/borg/cache_sync/cache_sync.c @@ -87,8 +87,10 @@ cache_sync_feed(CacheSyncCtx *ctx, void *data, uint32_t length) ctx->ctx.user.last_error = "cache_sync_feed: unable to allocate buffer"; return 0; } - memcpy(new_buf, ctx->buf + ctx->head, ctx->tail - ctx->head); - free(ctx->buf); + if(ctx->buf) { + memcpy(new_buf, ctx->buf + ctx->head, ctx->tail - ctx->head); + free(ctx->buf); + } ctx->buf = new_buf; ctx->tail -= ctx->head; ctx->head = 0;