Compare commits

...

5 Commits

Author SHA1 Message Date
Jordan Bancino 39c25e5a17 Merge pull request 'Copy filename into preallocated field with Cytoplasm's Memory API' (#33) from lda/Cytoplasm:direct-filenames into master
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Has been cancelled Details
Reviewed-on: Telodendria/Cytoplasm#33
2024-08-18 19:26:18 -04:00
Jordan Bancino 4903c075e8 Merge pull request 'Pre-emptively free out the key' (#41) from lda/Cytoplasm:hashmap-del-leak into master
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Has been cancelled Details
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Has been cancelled Details
Reviewed-on: Telodendria/Cytoplasm#41
2024-08-09 09:26:49 -04:00
LDA da857a3d53 [FIX] Pre-emptively free out the key
I fail to see a reason why this shouldn't be done, to be fair, and it
fixes a memory leakage with a Cytoplasm-based project I'm making.
2024-07-19 16:08:25 +02:00
lda 138ea1c8e9 [FIX] Oops. 2024-05-26 22:06:56 +02:00
lda cdf4430a9e [FIX] Fix issue with const strings which may be invalidated 2024-05-26 22:01:06 +02:00
2 changed files with 10 additions and 6 deletions

View File

@ -184,6 +184,8 @@ HashMapDelete(HashMap * map, const char *key)
if (bucket->hash == hash)
{
bucket->hash = 0;
Free(bucket->key);
bucket->key = NULL;
return bucket->value;
}

View File

@ -40,10 +40,12 @@
#define MEMORY_HEXDUMP_WIDTH 16
#endif
#define MEMORY_FILE_SIZE 256
struct MemoryInfo
{
size_t size;
const char *file;
char file[MEMORY_FILE_SIZE];
int line;
void *pointer;
};
@ -227,7 +229,7 @@ MemoryAllocate(size_t size, const char *file, int line)
MEM_BOUND_UPPER(p, size) = MEM_BOUND;
a->size = MEM_SIZE_ACTUAL(size);
a->file = file;
strncpy(a->file, file, MEMORY_FILE_SIZE - 1);
a->line = line;
a->pointer = p;
@ -270,7 +272,7 @@ MemoryReallocate(void *p, size_t size, const char *file, int line)
{
MemoryDelete(a);
a->size = MEM_SIZE_ACTUAL(size);
a->file = file;
strncpy(a->file, file, MEMORY_FILE_SIZE - 1);
a->line = line;
a->pointer = new;
@ -293,7 +295,7 @@ MemoryReallocate(void *p, size_t size, const char *file, int line)
if (a)
{
a->size = 0;
a->file = file;
strncpy(a->file, file, MEMORY_FILE_SIZE - 1);
a->line = line;
a->pointer = p;
hook(MEMORY_BAD_POINTER, a, hookArgs);
@ -322,7 +324,7 @@ MemoryFree(void *p, const char *file, int line)
pthread_mutex_lock(&lock);
if (hook)
{
a->file = file;
strncpy(a->file, file, MEMORY_FILE_SIZE - 1);
a->line = line;
hook(MEMORY_FREE, a, hookArgs);
}
@ -337,7 +339,7 @@ MemoryFree(void *p, const char *file, int line)
a = malloc(sizeof(MemoryInfo));
if (a)
{
a->file = file;
strncpy(a->file, file, MEMORY_FILE_SIZE - 1);
a->line = line;
a->size = 0;
a->pointer = p;