Migrate pfolder.c malloc/free to pmem_malloc/pmem_free
This commit is contained in:
parent
115cbba660
commit
f2c1ee615f
|
|
@ -41,6 +41,7 @@
|
||||||
#include "pfsfolder.h"
|
#include "pfsfolder.h"
|
||||||
#include "plibs.h"
|
#include "plibs.h"
|
||||||
#include "plist.h"
|
#include "plist.h"
|
||||||
|
#include "pmem.h"
|
||||||
#include "pnetlibs.h"
|
#include "pnetlibs.h"
|
||||||
#include "ppathstatus.h"
|
#include "ppathstatus.h"
|
||||||
#include "prun.h"
|
#include "prun.h"
|
||||||
|
|
@ -197,9 +198,9 @@ psync_folderid_t pfolder_id_create(const char *path) {
|
||||||
->num;
|
->num;
|
||||||
if (papi_find_result2(bres, "created", PARAM_BOOL)->num)
|
if (papi_find_result2(bres, "created", PARAM_BOOL)->num)
|
||||||
pdiff_wake();
|
pdiff_wake();
|
||||||
free(bres);
|
pmem_free(PMEM_SUBSYS_OTHER, bres);
|
||||||
} else {
|
} else {
|
||||||
free(bres);
|
pmem_free(PMEM_SUBSYS_OTHER, bres);
|
||||||
psync_process_api_error(result);
|
psync_process_api_error(result);
|
||||||
if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL)
|
if (psync_handle_api_result(result) == PSYNC_NET_TEMPFAIL)
|
||||||
goto errnet;
|
goto errnet;
|
||||||
|
|
@ -227,7 +228,7 @@ static void psync_free_string_list(psync_list *lst) {
|
||||||
|
|
||||||
static string_list *str_to_list_element(const char *str, size_t len) {
|
static string_list *str_to_list_element(const char *str, size_t len) {
|
||||||
string_list *le;
|
string_list *le;
|
||||||
le = (string_list *)malloc(sizeof(string_list) + len + 1);
|
le = (string_list *)pmem_malloc(PMEM_SUBSYS_OTHER, sizeof(string_list) + len + 1);
|
||||||
le->str = (char *)(le + 1);
|
le->str = (char *)(le + 1);
|
||||||
le->len = len;
|
le->len = len;
|
||||||
memcpy(le->str, str, len + 1);
|
memcpy(le->str, str, len + 1);
|
||||||
|
|
@ -242,7 +243,7 @@ static int psync_add_path_to_list(psync_list *lst, psync_folderid_t folderid) {
|
||||||
size_t len;
|
size_t len;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (folderid == 0) {
|
if (folderid == 0) {
|
||||||
e = (string_list *)malloc(sizeof(string_list));
|
e = (string_list *)pmem_malloc(PMEM_SUBSYS_OTHER, sizeof(string_list));
|
||||||
e->str = (char *)e;
|
e->str = (char *)e;
|
||||||
e->len = 0;
|
e->len = 0;
|
||||||
psync_list_add_head(lst, &e->list);
|
psync_list_add_head(lst, &e->list);
|
||||||
|
|
@ -270,18 +271,18 @@ static string_list *str_list_decode(psync_folderid_t folderid, string_list *e) {
|
||||||
char *fn;
|
char *fn;
|
||||||
dec = pcryptofolder_flddecoder_get(folderid);
|
dec = pcryptofolder_flddecoder_get(folderid);
|
||||||
if (psync_crypto_is_error(dec)) {
|
if (psync_crypto_is_error(dec)) {
|
||||||
free(e);
|
pmem_free(PMEM_SUBSYS_OTHER, e);
|
||||||
pdbg_logf(D_WARNING, "got error %d getting decoder for folderid %lu",
|
pdbg_logf(D_WARNING, "got error %d getting decoder for folderid %lu",
|
||||||
psync_crypto_to_error(dec), (unsigned long)folderid);
|
psync_crypto_to_error(dec), (unsigned long)folderid);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fn = pcryptofolder_flddecode_filename(dec, e->str);
|
fn = pcryptofolder_flddecode_filename(dec, e->str);
|
||||||
pcryptofolder_flddecoder_release(folderid, dec);
|
pcryptofolder_flddecoder_release(folderid, dec);
|
||||||
free(e);
|
pmem_free(PMEM_SUBSYS_OTHER, e);
|
||||||
if (pdbg_unlikely(!fn))
|
if (pdbg_unlikely(!fn))
|
||||||
return NULL;
|
return NULL;
|
||||||
e = str_to_list_element(fn, strlen(fn));
|
e = str_to_list_element(fn, strlen(fn));
|
||||||
free(fn);
|
pmem_free(PMEM_SUBSYS_OTHER, fn);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,7 +300,7 @@ static int psync_add_path_to_list_decode(psync_list *lst,
|
||||||
if (folderid == 0) {
|
if (folderid == 0) {
|
||||||
if (e)
|
if (e)
|
||||||
psync_list_add_head(lst, &e->list);
|
psync_list_add_head(lst, &e->list);
|
||||||
e = (string_list *)malloc(sizeof(string_list));
|
e = (string_list *)pmem_malloc(PMEM_SUBSYS_OTHER, sizeof(string_list));
|
||||||
e->str = (char *)e;
|
e->str = (char *)e;
|
||||||
e->len = 0;
|
e->len = 0;
|
||||||
psync_list_add_head(lst, &e->list);
|
psync_list_add_head(lst, &e->list);
|
||||||
|
|
@ -345,7 +346,7 @@ char *psync_join_string_list(const char *sep, psync_list *lst, size_t *retlen) {
|
||||||
if (unlikely(!cnt))
|
if (unlikely(!cnt))
|
||||||
return putil_strdup("");
|
return putil_strdup("");
|
||||||
seplen = strlen(sep);
|
seplen = strlen(sep);
|
||||||
ret = str = malloc(slen + cnt * seplen + 1);
|
ret = str = pmem_malloc(PMEM_SUBSYS_OTHER, slen + cnt * seplen + 1);
|
||||||
psync_list_for_each_element(e, lst, string_list, list) {
|
psync_list_for_each_element(e, lst, string_list, list) {
|
||||||
memcpy(str, e->str, e->len);
|
memcpy(str, e->str, e->len);
|
||||||
str += e->len;
|
str += e->len;
|
||||||
|
|
@ -374,7 +375,7 @@ char *pfolder_path(psync_folderid_t folderid, size_t *retlen) {
|
||||||
ret = psync_join_string_list("/", &folderlist, retlen);
|
ret = psync_join_string_list("/", &folderlist, retlen);
|
||||||
psync_free_string_list(&folderlist);
|
psync_free_string_list(&folderlist);
|
||||||
if (!ret[0]) {
|
if (!ret[0]) {
|
||||||
free(ret);
|
pmem_free(PMEM_SUBSYS_OTHER, ret);
|
||||||
ret = putil_strdup("/");
|
ret = putil_strdup("/");
|
||||||
if (retlen)
|
if (retlen)
|
||||||
*retlen = 1;
|
*retlen = 1;
|
||||||
|
|
@ -396,7 +397,7 @@ char *pfolder_path_sep(psync_folderid_t folderid, const char *sep,
|
||||||
ret = psync_join_string_list(sep, &folderlist, retlen);
|
ret = psync_join_string_list(sep, &folderlist, retlen);
|
||||||
psync_free_string_list(&folderlist);
|
psync_free_string_list(&folderlist);
|
||||||
if (!ret[0]) {
|
if (!ret[0]) {
|
||||||
free(ret);
|
pmem_free(PMEM_SUBSYS_OTHER, ret);
|
||||||
ret = putil_strdup(sep);
|
ret = putil_strdup(sep);
|
||||||
if (retlen)
|
if (retlen)
|
||||||
*retlen = 1;
|
*retlen = 1;
|
||||||
|
|
@ -544,10 +545,10 @@ char *pfolder_lpath_lfile(psync_fileid_t localfileid,
|
||||||
|
|
||||||
static folder_list *folder_list_init() {
|
static folder_list *folder_list_init() {
|
||||||
folder_list *list;
|
folder_list *list;
|
||||||
list = (folder_list *)malloc(sizeof(folder_list));
|
list = (folder_list *)pmem_malloc(PMEM_SUBSYS_OTHER, sizeof(folder_list));
|
||||||
list->entries =
|
list->entries =
|
||||||
(pentry_t *)malloc(sizeof(pentry_t) * INITIAL_ENTRY_CNT);
|
(pentry_t *)pmem_malloc_array(PMEM_SUBSYS_OTHER, INITIAL_ENTRY_CNT, sizeof(pentry_t));
|
||||||
list->namebuff = (char *)malloc(INITIAL_NAME_BUFF);
|
list->namebuff = (char *)pmem_malloc(PMEM_SUBSYS_OTHER, INITIAL_NAME_BUFF);
|
||||||
list->nameoff = 0;
|
list->nameoff = 0;
|
||||||
list->namealloc = INITIAL_NAME_BUFF;
|
list->namealloc = INITIAL_NAME_BUFF;
|
||||||
list->entriescnt = 0;
|
list->entriescnt = 0;
|
||||||
|
|
@ -572,9 +573,9 @@ static void folder_list_add(folder_list *list, pentry_t *entry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void folder_list_free(folder_list *list) {
|
static void folder_list_free(folder_list *list) {
|
||||||
free(list->entries);
|
pmem_free(PMEM_SUBSYS_OTHER, list->entries);
|
||||||
free(list->namebuff);
|
pmem_free(PMEM_SUBSYS_OTHER, list->namebuff);
|
||||||
free(list);
|
pmem_free(PMEM_SUBSYS_OTHER, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static pfolder_list_t *folder_list_finalize(folder_list *list) {
|
static pfolder_list_t *folder_list_finalize(folder_list *list) {
|
||||||
|
|
@ -585,7 +586,7 @@ static pfolder_list_t *folder_list_finalize(folder_list *list) {
|
||||||
(unsigned)(offsetof(pfolder_list_t, entries) +
|
(unsigned)(offsetof(pfolder_list_t, entries) +
|
||||||
sizeof(pentry_t) * list->entriescnt + list->nameoff),
|
sizeof(pentry_t) * list->entriescnt + list->nameoff),
|
||||||
(unsigned)list->nameoff);
|
(unsigned)list->nameoff);
|
||||||
ret = (pfolder_list_t *)malloc(offsetof(pfolder_list_t, entries) +
|
ret = (pfolder_list_t *)pmem_malloc(PMEM_SUBSYS_OTHER, offsetof(pfolder_list_t, entries) +
|
||||||
sizeof(pentry_t) * list->entriescnt +
|
sizeof(pentry_t) * list->entriescnt +
|
||||||
list->nameoff);
|
list->nameoff);
|
||||||
name = ((char *)ret) + offsetof(pfolder_list_t, entries) +
|
name = ((char *)ret) + offsetof(pfolder_list_t, entries) +
|
||||||
|
|
@ -731,7 +732,7 @@ pentry_t *pfolder_stat(const char *remotepath) {
|
||||||
if (remotepath[0] != '/')
|
if (remotepath[0] != '/')
|
||||||
return NULL;
|
return NULL;
|
||||||
if (remotepath[1] == 0) {
|
if (remotepath[1] == 0) {
|
||||||
ret = malloc(sizeof(pentry_t));
|
ret = pmem_malloc(PMEM_SUBSYS_OTHER, sizeof(pentry_t));
|
||||||
ret->name = "/";
|
ret->name = "/";
|
||||||
ret->namelen = 1;
|
ret->namelen = 1;
|
||||||
ret->isfolder = 1;
|
ret->isfolder = 1;
|
||||||
|
|
@ -746,11 +747,11 @@ pentry_t *pfolder_stat(const char *remotepath) {
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
folderid = 0;
|
folderid = 0;
|
||||||
else {
|
else {
|
||||||
cremotepath = malloc(sizeof(char) * (len + 1));
|
cremotepath = pmem_malloc(PMEM_SUBSYS_OTHER, sizeof(char) * (len + 1));
|
||||||
memcpy(cremotepath, remotepath, len + 1);
|
memcpy(cremotepath, remotepath, len + 1);
|
||||||
cremotepath[len] = 0;
|
cremotepath[len] = 0;
|
||||||
folderid = pfolder_id(cremotepath);
|
folderid = pfolder_id(cremotepath);
|
||||||
free(cremotepath);
|
pmem_free(PMEM_SUBSYS_OTHER, cremotepath);
|
||||||
if (folderid == PSYNC_INVALID_FOLDERID)
|
if (folderid == PSYNC_INVALID_FOLDERID)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -761,7 +762,7 @@ pentry_t *pfolder_stat(const char *remotepath) {
|
||||||
psql_bind_uint(res, 1, folderid);
|
psql_bind_uint(res, 1, folderid);
|
||||||
psql_bind_lstr(res, 2, remotepath + len, olen);
|
psql_bind_lstr(res, 2, remotepath + len, olen);
|
||||||
if ((row = psql_fetch_int(res))) {
|
if ((row = psql_fetch_int(res))) {
|
||||||
ret = (pentry_t *)malloc(sizeof(pentry_t) + olen + 1);
|
ret = (pentry_t *)pmem_malloc(PMEM_SUBSYS_OTHER, sizeof(pentry_t) + olen + 1);
|
||||||
ret->folder.folderid = row[0];
|
ret->folder.folderid = row[0];
|
||||||
ret->folder.cansyncup = ((row[1] & PSYNC_PERM_WRITE) == PSYNC_PERM_WRITE);
|
ret->folder.cansyncup = ((row[1] & PSYNC_PERM_WRITE) == PSYNC_PERM_WRITE);
|
||||||
ret->folder.cansyncdown = ((row[1] & PSYNC_PERM_READ) == PSYNC_PERM_READ);
|
ret->folder.cansyncdown = ((row[1] & PSYNC_PERM_READ) == PSYNC_PERM_READ);
|
||||||
|
|
@ -780,7 +781,7 @@ pentry_t *pfolder_stat(const char *remotepath) {
|
||||||
psql_bind_uint(res, 1, folderid);
|
psql_bind_uint(res, 1, folderid);
|
||||||
psql_bind_lstr(res, 2, remotepath + len, olen);
|
psql_bind_lstr(res, 2, remotepath + len, olen);
|
||||||
if ((row = psql_fetch_int(res))) {
|
if ((row = psql_fetch_int(res))) {
|
||||||
ret = (pentry_t *)malloc(sizeof(pentry_t) + olen + 1);
|
ret = (pentry_t *)pmem_malloc(PMEM_SUBSYS_OTHER, sizeof(pentry_t) + olen + 1);
|
||||||
ret->file.fileid = row[0];
|
ret->file.fileid = row[0];
|
||||||
ret->file.size = row[1];
|
ret->file.size = row[1];
|
||||||
ret->name = (char *)(ret + 1);
|
ret->name = (char *)(ret + 1);
|
||||||
|
|
@ -842,7 +843,7 @@ psync_folder_list_t *pfolder_sync_folders(char *syncTypes) {
|
||||||
}
|
}
|
||||||
cstr = psync_get_lstring(row[2], &l);
|
cstr = psync_get_lstring(row[2], &l);
|
||||||
l++;
|
l++;
|
||||||
str = (char *)malloc(l);
|
str = (char *)pmem_malloc(PMEM_SUBSYS_OTHER, l);
|
||||||
memcpy(str, cstr, l);
|
memcpy(str, cstr, l);
|
||||||
|
|
||||||
strlens += l;
|
strlens += l;
|
||||||
|
|
@ -866,14 +867,14 @@ psync_folder_list_t *pfolder_sync_folders(char *syncTypes) {
|
||||||
psql_free(res);
|
psql_free(res);
|
||||||
l = offsetof(psync_folder_list_t, folders) +
|
l = offsetof(psync_folder_list_t, folders) +
|
||||||
sizeof(psync_folder_t) * lastfolder;
|
sizeof(psync_folder_t) * lastfolder;
|
||||||
ret = (psync_folder_list_t *)malloc(l + strlens);
|
ret = (psync_folder_list_t *)pmem_malloc(PMEM_SUBSYS_OTHER, l + strlens);
|
||||||
str = ((char *)ret) + l;
|
str = ((char *)ret) + l;
|
||||||
ret->foldercnt = lastfolder;
|
ret->foldercnt = lastfolder;
|
||||||
|
|
||||||
for (i = 0; i < lastfolder; i++) {
|
for (i = 0; i < lastfolder; i++) {
|
||||||
l = folders[i].locallen;
|
l = folders[i].locallen;
|
||||||
memcpy(str, folders[i].localpath, l);
|
memcpy(str, folders[i].localpath, l);
|
||||||
free(folders[i].localpath);
|
pmem_free(PMEM_SUBSYS_OTHER, folders[i].localpath);
|
||||||
strncpy(ret->folders[i].localpath, str,
|
strncpy(ret->folders[i].localpath, str,
|
||||||
sizeof(ret->folders[i].localpath) - 1);
|
sizeof(ret->folders[i].localpath) - 1);
|
||||||
ret->folders[i].localpath[sizeof(ret->folders[i].localpath) - 1] = '\0';
|
ret->folders[i].localpath[sizeof(ret->folders[i].localpath) - 1] = '\0';
|
||||||
|
|
@ -893,7 +894,7 @@ psync_folder_list_t *pfolder_sync_folders(char *syncTypes) {
|
||||||
|
|
||||||
l = folders[i].remotelen;
|
l = folders[i].remotelen;
|
||||||
memcpy(str, folders[i].remotepath, l);
|
memcpy(str, folders[i].remotepath, l);
|
||||||
free(folders[i].remotepath);
|
pmem_free(PMEM_SUBSYS_OTHER, folders[i].remotepath);
|
||||||
strncpy(ret->folders[i].remotepath, str,
|
strncpy(ret->folders[i].remotepath, str,
|
||||||
sizeof(ret->folders[i].remotepath) - 1);
|
sizeof(ret->folders[i].remotepath) - 1);
|
||||||
ret->folders[i].remotepath[sizeof(ret->folders[i].remotepath) - 1] = '\0';
|
ret->folders[i].remotepath[sizeof(ret->folders[i].remotepath) - 1] = '\0';
|
||||||
|
|
@ -916,7 +917,7 @@ psync_folder_list_t *pfolder_sync_folders(char *syncTypes) {
|
||||||
ret->folders[i].synctype = folders[i].synctype;
|
ret->folders[i].synctype = folders[i].synctype;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(folders);
|
pmem_free(PMEM_SUBSYS_OTHER, folders);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -951,10 +952,10 @@ psync_syncid_t pfolder_add_sync(const char *localpath, psync_folderid_t folderid
|
||||||
if (!memcmp(syncmp, localpath, len) &&
|
if (!memcmp(syncmp, localpath, len) &&
|
||||||
(localpath[len] == 0 || localpath[len] == '/' ||
|
(localpath[len] == 0 || localpath[len] == '/' ||
|
||||||
localpath[len] == '\\')) {
|
localpath[len] == '\\')) {
|
||||||
free(syncmp);
|
pmem_free(PMEM_SUBSYS_OTHER, syncmp);
|
||||||
return_isyncid(PERROR_LOCAL_IS_ON_PDRIVE);
|
return_isyncid(PERROR_LOCAL_IS_ON_PDRIVE);
|
||||||
}
|
}
|
||||||
free(syncmp);
|
pmem_free(PMEM_SUBSYS_OTHER, syncmp);
|
||||||
}
|
}
|
||||||
res = psql_query("SELECT localpath FROM syncfolder");
|
res = psql_query("SELECT localpath FROM syncfolder");
|
||||||
if (pdbg_unlikely(!res))
|
if (pdbg_unlikely(!res))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue