memleak fixes (#40)
* fixed 2 of the 3 memory leaks * fixed more memleaks * more leaks * another one * BUGHUNT mode to look for more mem leaks
This commit is contained in:
parent
bec97722cd
commit
8d3c496754
2
Makefile
2
Makefile
|
|
@ -1,4 +1,4 @@
|
|||
CFLAGS=-fPIC -Wall -O2 -g -fsanitize=address -I./pclsync -I./poverlay_linux -I/usr/include -I/usr/include/mbedtls2
|
||||
CFLAGS=-fPIC -Wall -O0 -g -fsanitize=address -I./pclsync -I./poverlay_linux -I/usr/include -I/usr/include/mbedtls2
|
||||
LDFLAGS=-lboost_program_options -lssl -lcrypto -lfuse -lpthread -ludev -lsqlite3 -lz -l:libmbedtls.so.14 -l:libmbedx509.so.1 -l:libmbedcrypto.so.7
|
||||
CMDSRC=control_tools.cpp pclsync_lib_c.cpp pclsync_lib.cpp main.cpp
|
||||
DESTDIR=/usr/local
|
||||
|
|
|
|||
|
|
@ -270,8 +270,9 @@ int check_user_relocated(uint64_t luserid, psync_socket *sock) {
|
|||
id = userids->array[i];
|
||||
userid = psync_find_result(id, "userid", PARAM_NUM)->num;
|
||||
lid = psync_find_result(id, "locationid", PARAM_NUM)->num;
|
||||
if (luserid == userid && lid == clid)
|
||||
if (luserid == userid && lid == clid) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -774,6 +775,7 @@ static psync_socket *get_connected_socket() {
|
|||
psync_sql_sync();
|
||||
}
|
||||
|
||||
psync_free(chrUserid);
|
||||
psync_free(auth);
|
||||
psync_free(user);
|
||||
psync_free(pass);
|
||||
|
|
@ -2531,8 +2533,7 @@ static void process_modifyaccountinfo(const binresult *entry) {
|
|||
psync_find_result(res, "cryptosetup", PARAM_BOOL)->num);
|
||||
}
|
||||
|
||||
#define FN(n) \
|
||||
{ process_##n, #n, sizeof(#n) - 1, 0 }
|
||||
#define FN(n) {process_##n, #n, sizeof(#n) - 1, 0}
|
||||
|
||||
static struct {
|
||||
void (*process)(const binresult *);
|
||||
|
|
@ -3132,7 +3133,7 @@ restart:
|
|||
psync_notifications_notify(res);
|
||||
} else if (entries->length == 8 && !strcmp(entries->str, "publinks")) {
|
||||
ids.publinkid = psync_find_result(res, "publinkid", PARAM_NUM)->num;
|
||||
ret = cache_links(&err);
|
||||
ret = cache_links(err, 256);
|
||||
if (ret < 0)
|
||||
debug(D_ERROR, "Cacheing links faild with err %s", err);
|
||||
else
|
||||
|
|
@ -3167,6 +3168,7 @@ restart:
|
|||
debug(D_NOTICE, "got no from, did we send a nop recently?");
|
||||
}
|
||||
}
|
||||
psync_free(res);
|
||||
}
|
||||
psync_socket_close(sock);
|
||||
psync_pipe_close(exceptionsock);
|
||||
|
|
|
|||
|
|
@ -3482,6 +3482,7 @@ static void psync_fs_do_stop(void) {
|
|||
#if IS_DEBUG
|
||||
psync_fs_dump_internals();
|
||||
#endif
|
||||
psync_free(mp);
|
||||
}
|
||||
pthread_mutex_unlock(&start_mutex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <execinfo.h>
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
#include <mbedtls/debug.h>
|
||||
#include <mbedtls/entropy.h>
|
||||
|
|
@ -80,6 +81,8 @@
|
|||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BUGHUNT 0
|
||||
|
||||
// Variable containing UNIX time of the last backup file deleted event
|
||||
time_t lastBupDelEventTime = 0;
|
||||
time_t bupNotifDelay = 300;
|
||||
|
|
@ -135,13 +138,25 @@ PSYNC_NOINLINE void *psync_emergency_malloc(size_t size) {
|
|||
}
|
||||
|
||||
void *psync_malloc(size_t size) {
|
||||
void *ret;
|
||||
ret = psync_real_malloc(size);
|
||||
if (likely(ret))
|
||||
void *ptr;
|
||||
#if 1 == BUGHUNT
|
||||
void *callstack[128];
|
||||
int frames = backtrace(callstack, 128);
|
||||
char **strs = backtrace_symbols(callstack, frames);
|
||||
#endif
|
||||
ptr = psync_real_malloc(size);
|
||||
#if 1 == BUGHUNT
|
||||
printf("Allocated %zu bytes at %p\n", size, ptr);
|
||||
for (int i = 0; i < frames; i++) {
|
||||
printf("%s\n", strs[i]);
|
||||
}
|
||||
free(strs);
|
||||
#endif
|
||||
if (likely(ptr))
|
||||
#if IS_DEBUG
|
||||
return memset(ret, 0xfa, size);
|
||||
return memset(ptr, 0xfa, size);
|
||||
#else
|
||||
return ret;
|
||||
return ptr;
|
||||
#endif
|
||||
else
|
||||
return psync_emergency_malloc(size);
|
||||
|
|
|
|||
|
|
@ -419,7 +419,7 @@ void send_psyncs_event(const char *binapi, const char *auth) {
|
|||
int intRes;
|
||||
int syncCnt = 0;
|
||||
|
||||
errMsg = (char *)malloc(1024 * sizeof(char));
|
||||
errMsg = (char *)psync_malloc(1024 * sizeof(char));
|
||||
errMsg[0] = 0;
|
||||
|
||||
time(&rawtime);
|
||||
|
|
@ -433,11 +433,11 @@ void send_psyncs_event(const char *binapi, const char *auth) {
|
|||
|
||||
if (syncCnt < 1) {
|
||||
debug(D_NOTICE, "No syncs, skip the event.");
|
||||
|
||||
psync_free(errMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
eventParams params = {1, // Number of parameters we are passing below.
|
||||
eventParams params = {1, // Number of parameters passed below
|
||||
{P_NUM(PSYNC_SYNCS_COUNT, syncCnt)}};
|
||||
|
||||
intRes = create_backend_event(binapi,
|
||||
|
|
@ -448,13 +448,14 @@ void send_psyncs_event(const char *binapi, const char *auth) {
|
|||
|
||||
debug(D_NOTICE, "Syncs Count Event Result:[%d], Message: [%s] .", intRes,
|
||||
errMsg);
|
||||
psync_free(errMsg);
|
||||
|
||||
sql = psync_sql_prep_statement(
|
||||
"REPLACE INTO setting (id, value) VALUES ('syncEventSentFlag', ?)");
|
||||
psync_sql_bind_uint(sql, 1, 1);
|
||||
psync_sql_run_free(sql);
|
||||
}
|
||||
|
||||
psync_free(errMsg);
|
||||
}
|
||||
|
||||
int set_be_file_dates(uint64_t fileid, time_t ctime, time_t mtime) {
|
||||
|
|
|
|||
|
|
@ -553,7 +553,7 @@ int64_t do_psync_tree_public_link(const char *linkname, const char *root,
|
|||
return result;
|
||||
}
|
||||
|
||||
int cache_links(char **err /*OUT*/) {
|
||||
int cache_links(char *err, size_t err_size /*OUT*/) {
|
||||
psync_socket *api;
|
||||
binresult *bres;
|
||||
uint64_t result;
|
||||
|
|
@ -566,7 +566,6 @@ int cache_links(char **err /*OUT*/) {
|
|||
q = psync_sql_prep_statement("DELETE FROM links WHERE isincomming = 0 ");
|
||||
psync_sql_run_free(q);
|
||||
|
||||
*err = 0;
|
||||
if (psync_my_auth[0]) {
|
||||
binparam params[] = {P_STR("auth", psync_my_auth),
|
||||
P_STR("timeformat", "timestamp"),
|
||||
|
|
@ -574,7 +573,8 @@ int cache_links(char **err /*OUT*/) {
|
|||
api = psync_apipool_get();
|
||||
if (unlikely(!api)) {
|
||||
debug(D_WARNING, "Can't gat api from the pool. No pool ?\n");
|
||||
*err = psync_strndup("Connection error.", 17);
|
||||
//*err = psync_strndup("Connection error.", 17);
|
||||
snprintf(err, err_size, "Connection error.");
|
||||
return -2;
|
||||
}
|
||||
bres = send_command(api, "listpublinks", params);
|
||||
|
|
@ -586,31 +586,39 @@ int cache_links(char **err /*OUT*/) {
|
|||
api = psync_apipool_get();
|
||||
if (unlikely(!api)) {
|
||||
debug(D_WARNING, "Can't gat api from the pool. No pool ?\n");
|
||||
*err = psync_strndup("Connection error.", 17);
|
||||
//*err = psync_strndup("Connection error.", 17);
|
||||
snprintf(err, err_size, "Connection error.");
|
||||
return -2;
|
||||
}
|
||||
bres = send_command(api, "listpublinks", params);
|
||||
} else
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (likely(bres))
|
||||
psync_apipool_release(api);
|
||||
else {
|
||||
psync_apipool_release_bad(api);
|
||||
debug(D_WARNING, "Send command returned in valid result.\n");
|
||||
*err = psync_strndup("Connection error.", 17);
|
||||
//*err = psync_strndup("Connection error.", 17);
|
||||
snprintf(err, err_size, "Connection error.");
|
||||
psync_free(bres);
|
||||
return 0;
|
||||
}
|
||||
result = psync_find_result(bres, "result", PARAM_NUM)->num;
|
||||
if (unlikely(result)) {
|
||||
errorret = psync_find_result(bres, "error", PARAM_STR)->str;
|
||||
*err = psync_strndup(errorret, strlen(errorret));
|
||||
//*err = psync_strndup(errorret, strlen(errorret));
|
||||
snprintf(err, err_size, "%s", errorret);
|
||||
debug(D_WARNING, "command listpublinks returned error code %u",
|
||||
(unsigned)result);
|
||||
psync_process_api_error(result);
|
||||
psync_free(bres);
|
||||
if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL)
|
||||
return -result;
|
||||
else {
|
||||
*err = psync_strndup("Connection error.", 17);
|
||||
//*err = psync_strndup("Connection error.", 17);
|
||||
snprintf(err, err_size, "Connection error.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -700,6 +708,8 @@ int cache_links(char **err /*OUT*/) {
|
|||
|
||||
psync_sql_run_free(q);
|
||||
}
|
||||
|
||||
psync_free(bres);
|
||||
return linkscnt;
|
||||
}
|
||||
|
||||
|
|
@ -1299,7 +1309,7 @@ void cache_links_all() {
|
|||
|
||||
ret = cache_upload_links(&err);
|
||||
if (ret >= 0)
|
||||
ret += cache_links(&err);
|
||||
ret += cache_links(err, 256);
|
||||
|
||||
if (ret < 0) {
|
||||
if (err) {
|
||||
|
|
@ -1308,6 +1318,8 @@ void cache_links_all() {
|
|||
psync_free(err);
|
||||
}
|
||||
}
|
||||
if (err)
|
||||
psync_free(err);
|
||||
}
|
||||
|
||||
int do_delete_all_links(int64_t folderid, int64_t fileid, char **err) {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ plink_contents_t *do_show_link(const char *code, char **err /*OUT*/);
|
|||
|
||||
void cache_links_all();
|
||||
int cache_upload_links(char **err /*OUT*/);
|
||||
int cache_links(char **err /*OUT*/);
|
||||
int cache_links(char *err, size_t err_size /*OUT*/);
|
||||
|
||||
int do_delete_all_folder_links(psync_folderid_t folderid, char **err);
|
||||
int do_delete_all_file_links(psync_fileid_t fileid, char **err);
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ static void status_change(pstatus_t *status) {
|
|||
static int cryptocheck = 0;
|
||||
|
||||
char *err;
|
||||
err = (char *)malloc(1024);
|
||||
err = (char *)psync_malloc(1024);
|
||||
|
||||
std::cout << "Down: " << status->downloadstr << "| Up: " << status->uploadstr
|
||||
<< ", status is " << status2string(status->status) << std::endl;
|
||||
|
|
@ -265,6 +265,9 @@ static void status_change(pstatus_t *status) {
|
|||
clib::pclsync_lib::get_lib().status_callback_(
|
||||
(int)status->status, status2string(status->status));
|
||||
}
|
||||
|
||||
if (err)
|
||||
psync_free(err);
|
||||
}
|
||||
|
||||
int clib::pclsync_lib::start_crypto(const char *pass, void *rep) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue