libqaeda

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit cce716ca44feeacd98ff7e5944ffc9f238e3b4ac
parent dcb34072eddffcb78c5ef0ccafd3bd183809df8f
Author: lash <dev@holbrook.no>
Date:   Mon, 31 Mar 2025 00:11:33 +0100

Use correct store freer

Diffstat:
Msrc/cli/Makefile | 8++++----
Msrc/crypto/gcrypt.c | 10+++++-----
Msrc/store/file.c | 7++-----
Msrc/store/mem.c | 17+++++++++--------
4 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/src/cli/Makefile b/src/cli/Makefile @@ -1,9 +1,9 @@ INCLUDES := -I.. -I../lq -I../aux/include CFLAGS += $(INCLUDES) -Wall -#OBJFILES += ../asn1/*.o ../*.o ../lq/*.o ../store/file.o ../mem/std.o ../io/std.o ../crypto/gcrypt.o -OBJFILES += ../asn1/*.o ../*.o ../lq/*.o ../store/mem.o ../mem/std.o ../io/std.o ../crypto/gcrypt.o -#LIBS := `pkg-config --libs libtasn1 libgcrypt libxdg-basedir` -L../aux/lib -llash -lcwalk -LIBS := `pkg-config --libs libtasn1 libgcrypt libxdg-basedir` -L../aux/lib -llash -lcwalk -lhashmap +OBJFILES += ../asn1/*.o ../*.o ../lq/*.o ../store/file.o ../mem/std.o ../io/std.o ../crypto/gcrypt.o +#OBJFILES += ../asn1/*.o ../*.o ../lq/*.o ../store/mem.o ../mem/std.o ../io/std.o ../crypto/gcrypt.o +LIBS := `pkg-config --libs libtasn1 libgcrypt libxdg-basedir` -L../aux/lib -llash -lcwalk +#LIBS := `pkg-config --libs libtasn1 libgcrypt libxdg-basedir` -L../aux/lib -llash -lcwalk -lhashmap LDFLAGS += -L../aux/lib -L../ $(LIBS) all: diff --git a/src/crypto/gcrypt.c b/src/crypto/gcrypt.c @@ -68,9 +68,10 @@ static LQStore *gpg_key_store; int lq_crypto_init(const char *base) { int r; int l = 0; - char *p = NULL; + char *p; char path[LQ_PATH_MAX]; + lq_zero(path, LQ_PATH_MAX); if (gpg_version == NULL) { gpg_version = (char*)gcry_check_version(GPG_MIN_VERSION); if (gpg_version == NULL) { @@ -90,10 +91,9 @@ int lq_crypto_init(const char *base) { p = path; l = strlen(base); lq_cpy(p, base, l); - p += l; - if (*p != '/') { - *p = '/'; - *(p+1) = 0; + if (path[l] != '/') { + path[l] = '/'; + path[l+1] = 0; } r = lq_config_set(gpg_cfg_idx_dir, path); diff --git a/src/store/file.c b/src/store/file.c @@ -125,6 +125,8 @@ int lq_file_content_put(enum payload_e typ, LQStore *store, const char *key, siz } void lq_file_content_free(LQStore *store) { + lq_free(store->userdata); + lq_free(store); } struct lq_store_t LQFileContent = { @@ -148,11 +150,6 @@ LQStore* lq_store_new(const char *spec) { return store; } -void lq_store_free(LQStore *store) { - lq_free(store->userdata); - lq_free(store); -} - //LQStore* lq_file_content_new(const char *dir) { // char path[1024]; // LQStore *store; diff --git a/src/store/mem.c b/src/store/mem.c @@ -11,9 +11,9 @@ static const int store_typ_mem = 2; struct pair_t { - const char *key; + char *key; size_t key_len; - const char *val; + char *val; size_t val_len; }; @@ -57,6 +57,8 @@ static void free_item(void *o) { v = (struct pair_t*)o; debug_x(LLOG_DEBUG, "store.mem", "freeing key", 1, MORGEL_TYP_BIN, v->key_len, "key", v->key); + lq_free(v->key); + lq_free(v->val); lq_free((void*)v); } @@ -109,10 +111,12 @@ int lq_mem_content_put(enum payload_e typ, LQStore *store, const char *key, size path[0] = (char)typ; lq_cpy(path+1, key, *key_len); - v->key = path; + v->key = lq_alloc(LQ_STORE_KEY_MAX); v->key_len = *key_len + 1; - v->val = value; + lq_cpy(v->key, path, v->key_len); + v->val = lq_alloc(LQ_STORE_VAL_MAX); v->val_len = value_len; + lq_cpy(v->val, value, value_len); debug_x(LLOG_DEBUG, "store.mem", "store put req", 2, MORGEL_TYP_BIN, v->key_len, "key", v->key, MORGEL_TYP_NUM, 0, "bytes", value_len); @@ -130,10 +134,10 @@ int lq_mem_content_put(enum payload_e typ, LQStore *store, const char *key, size void lq_mem_content_free(LQStore *store) { if (store->userdata != NULL) { - hashmap_clear((struct hashmap*)store->userdata, false); hashmap_free((struct hashmap*)store->userdata); store->userdata = NULL; } + lq_free(store); } struct lq_store_t LQMemContent = { @@ -153,6 +157,3 @@ LQStore* lq_store_new(const char *spec) { store->userdata = NULL; return store; } - -void lq_store_free(LQStore *store) { -}