mirror of
https://github.com/isar/libmdbx.git
synced 2025-08-29 23:12:35 +08:00
mdbx: add mdbx_malloc/mdbx_free, etc.
1 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43 Change-Id: Ia5204be9f943fefde42e6a46e652c1be6ab6a96b
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* mdbx_chk.c - memory-mapped database check tool */
|
||||
/* mdbx_chk.c - memory-mapped database check tool */
|
||||
|
||||
/*
|
||||
* Copyright 2015-2018 Leonid Yuriev <leo@yuriev.ru>
|
||||
@@ -141,12 +141,12 @@ static void
|
||||
static void pagemap_cleanup(void) {
|
||||
for (int i = CORE_DBS; ++i < MAX_DBI;) {
|
||||
if (walk.dbi[i].name) {
|
||||
free((void *)walk.dbi[i].name);
|
||||
mdbx_free((void *)walk.dbi[i].name);
|
||||
walk.dbi[i].name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
free(walk.pagemap);
|
||||
mdbx_free(walk.pagemap);
|
||||
walk.pagemap = NULL;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ static void
|
||||
break;
|
||||
|
||||
if (!p) {
|
||||
p = calloc(1, sizeof(*p));
|
||||
p = mdbx_calloc(1, sizeof(*p));
|
||||
p->caption = msg;
|
||||
p->pr_next = problems_list;
|
||||
problems_list = p;
|
||||
@@ -233,7 +233,7 @@ static uint64_t problems_pop(struct problem *list) {
|
||||
count += problems_list->count;
|
||||
print("%s%s (%" PRIu64 ")", i ? ", " : "", problems_list->caption,
|
||||
problems_list->count);
|
||||
free(problems_list);
|
||||
mdbx_free(problems_list);
|
||||
problems_list = p;
|
||||
}
|
||||
print("\n");
|
||||
@@ -497,13 +497,13 @@ static int handle_maindb(const uint64_t record_number, const MDBX_val *key,
|
||||
return handle_userdb(record_number, key, data);
|
||||
}
|
||||
|
||||
name = malloc(key->iov_len + 1);
|
||||
name = mdbx_malloc(key->iov_len + 1);
|
||||
memcpy(name, key->iov_base, key->iov_len);
|
||||
name[key->iov_len] = '\0';
|
||||
userdb_count++;
|
||||
|
||||
rc = process_db(~0u, name, handle_userdb, false);
|
||||
free(name);
|
||||
mdbx_free(name);
|
||||
if (rc != MDBX_INCOMPATIBLE)
|
||||
return rc;
|
||||
|
||||
@@ -1093,7 +1093,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
print("Traversal b-tree by txn#%" PRIaTXN "...\n", txn->mt_txnid);
|
||||
fflush(NULL);
|
||||
walk.pagemap = calloc((size_t)lastpgno, sizeof(*walk.pagemap));
|
||||
walk.pagemap = mdbx_calloc((size_t)lastpgno, sizeof(*walk.pagemap));
|
||||
if (!walk.pagemap) {
|
||||
rc = errno ? errno : MDBX_ENOMEM;
|
||||
error("calloc failed, error %d %s\n", rc, mdbx_strerror(rc));
|
||||
|
@@ -292,7 +292,7 @@ int main(int argc, char *argv[]) {
|
||||
if (memchr(key.iov_base, '\0', key.iov_len))
|
||||
continue;
|
||||
count++;
|
||||
str = malloc(key.iov_len + 1);
|
||||
str = mdbx_malloc(key.iov_len + 1);
|
||||
memcpy(str, key.iov_base, key.iov_len);
|
||||
str[key.iov_len] = '\0';
|
||||
rc = mdbx_dbi_open(txn, str, 0, &db2);
|
||||
@@ -307,7 +307,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
mdbx_dbi_close(env, db2);
|
||||
}
|
||||
free(str);
|
||||
mdbx_free(str);
|
||||
if (rc)
|
||||
continue;
|
||||
}
|
||||
|
@@ -110,7 +110,7 @@ static void readhdr(void) {
|
||||
if (ptr)
|
||||
*ptr = '\0';
|
||||
if (subname)
|
||||
free(subname);
|
||||
mdbx_free(subname);
|
||||
subname = strdup((char *)dbuf.iov_base + STRLENOF("database="));
|
||||
} else if (!strncmp(dbuf.iov_base, "type=", STRLENOF("type="))) {
|
||||
if (strncmp((char *)dbuf.iov_base + STRLENOF("type="), "btree",
|
||||
@@ -237,7 +237,7 @@ static int readline(MDBX_val *out, MDBX_val *buf) {
|
||||
|
||||
/* Is buffer too short? */
|
||||
while (c1[len - 1] != '\n') {
|
||||
buf->iov_base = realloc(buf->iov_base, buf->iov_len * 2);
|
||||
buf->iov_base = mdbx_realloc(buf->iov_base, buf->iov_len * 2);
|
||||
if (!buf->iov_base) {
|
||||
Eof = 1;
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": out of memory, line too long\n",
|
||||
@@ -378,7 +378,7 @@ int main(int argc, char *argv[]) {
|
||||
#endif /* !WINDOWS */
|
||||
|
||||
dbuf.iov_len = 4096;
|
||||
dbuf.iov_base = malloc(dbuf.iov_len);
|
||||
dbuf.iov_base = mdbx_malloc(dbuf.iov_len);
|
||||
|
||||
if (!(mode & NOHDR))
|
||||
readhdr();
|
||||
@@ -418,7 +418,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
kbuf.iov_len = mdbx_env_get_maxkeysize(env) * 2 + 2;
|
||||
kbuf.iov_base = malloc(kbuf.iov_len);
|
||||
kbuf.iov_base = mdbx_malloc(kbuf.iov_len);
|
||||
|
||||
while (!Eof) {
|
||||
if (user_break) {
|
||||
|
@@ -356,13 +356,13 @@ int main(int argc, char *argv[]) {
|
||||
MDBX_dbi db2;
|
||||
if (memchr(key.iov_base, '\0', key.iov_len))
|
||||
continue;
|
||||
str = malloc(key.iov_len + 1);
|
||||
str = mdbx_malloc(key.iov_len + 1);
|
||||
memcpy(str, key.iov_base, key.iov_len);
|
||||
str[key.iov_len] = '\0';
|
||||
rc = mdbx_dbi_open(txn, str, 0, &db2);
|
||||
if (rc == MDBX_SUCCESS)
|
||||
printf("Status of %s\n", str);
|
||||
free(str);
|
||||
mdbx_free(str);
|
||||
if (rc)
|
||||
continue;
|
||||
rc = mdbx_dbi_stat(txn, db2, &mst, sizeof(mst));
|
||||
|
Reference in New Issue
Block a user