Skip to content

Commit a8aa6b2

Browse files
committed
test: improved test and a fix for the memdebug_realloc func
1 parent f735046 commit a8aa6b2

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/network.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ NETWORK_RESULT network_receive_buffer (network_data *data, const char *endpoint,
188188
if (rc == CURLE_OK) {
189189
buffer = netdata.buffer;
190190
blen = netdata.bused;
191-
} else {
192-
if (netdata.buffer) cloudsync_memory_free(netdata.buffer);
191+
} else if (netdata.buffer) {
192+
cloudsync_memory_free(netdata.buffer);
193+
netdata.buffer = NULL;
193194
}
194195

195196
cleanup:

src/utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ void *memdebug_realloc (void *ptr, sqlite3_uint64 new_size) {
515515
}
516516

517517
void *back_ptr = ptr;
518-
void *new_ptr = realloc(ptr, new_size);
518+
void *new_ptr = sqlite3_realloc64(ptr, new_size);
519519
if (!new_ptr) {
520520
BUILD_ERROR("Unable to reallocate a block of %lld bytes.", new_size);
521521
BUILD_STACK(n, stack);

test/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
#define EXT_PATH "./dist/cloudsync"
3838
#define RCHECK if (rc != SQLITE_OK) goto abort_test;
3939
#define ERROR_MSG if (rc != SQLITE_OK) printf("Error: %s\n", sqlite3_errmsg(db));
40-
#define ABORT_TEST abort_test: ERROR_MSG if (db) sqlite3_close(db); return rc;
40+
#define TERMINATE if (db) { db_exec(db, "SELECT cloudsync_terminate();"); }
41+
#define ABORT_TEST abort_test: ERROR_MSG TERMINATE if (db) sqlite3_close(db); return rc;
4142

4243
typedef enum { PRINT, NOPRINT, INTGR, GT0 } expected_type;
4344

@@ -305,6 +306,8 @@ int test_enable_disable(const char *db_path) {
305306
snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM users WHERE name='%s-should-sync';", value);
306307
rc = db_expect_int(db2, sql, 1); RCHECK
307308

309+
rc = db_exec(db2, "SELECT cloudsync_terminate();"); RCHECK
310+
308311
sqlite3_close(db2);
309312

310313
ABORT_TEST
@@ -356,6 +359,8 @@ void* worker(void* arg) {
356359
int main (void) {
357360
int rc = SQLITE_OK;
358361

362+
cloudsync_memory_init(1);
363+
359364
printf("\n\nIntegration Test ");
360365
rc += version();
361366
printf("===========================================\n");
@@ -461,6 +466,8 @@ int main (void) {
461466
}
462467
#endif // PEERS
463468

469+
cloudsync_memory_finalize();
470+
464471
printf("\n");
465472
return rc;
466473
}

0 commit comments

Comments
 (0)