Skip to content

Commit 21dd681

Browse files
committed
Fix a bug while expanding the buffer used in cloudsync_payload_encode_step
The bug was detected for payloads >= 500KB
1 parent 4b0729a commit 21dd681

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/cloudsync.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,12 +1907,11 @@ bool cloudsync_buffer_check (cloudsync_network_payload *payload, size_t needed)
19071907
// alloc/resize buffer
19081908
if (payload->bused + needed > payload->balloc) {
19091909
if (needed < CLOUDSYNC_PAYLOAD_MINBUF_SIZE) needed = CLOUDSYNC_PAYLOAD_MINBUF_SIZE;
1910-
size_t balloc = (payload->balloc * 2) + needed;
1910+
size_t balloc = payload->balloc + needed;
19111911

1912-
char *buffer = cloudsync_memory_alloc(balloc);
1912+
char *buffer = cloudsync_memory_realloc(payload->buffer, balloc);
19131913
if (!buffer) return cloudsync_buffer_free(payload);
19141914

1915-
if (payload->buffer) cloudsync_memory_free(payload->buffer);
19161915
payload->buffer = buffer;
19171916
payload->balloc = balloc;
19181917
if (payload->nrows == 0) payload->bused = sizeof(cloudsync_network_header);

src/cloudsync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "sqlite3.h"
1717
#endif
1818

19-
#define CLOUDSYNC_VERSION "0.8.4"
19+
#define CLOUDSYNC_VERSION "0.8.5"
2020

2121
int sqlite3_cloudsync_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);
2222

0 commit comments

Comments
 (0)