diff dowa/d_memory.c @ 36:84672efec192

[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
author MrJuneJune <me@mrjunejune.com>
date Sun, 09 Nov 2025 06:25:16 -0800
parents 08a465eec50b
children 636eab07809d
line wrap: on
line diff
--- a/dowa/d_memory.c	Thu Oct 30 09:53:22 2025 -0700
+++ b/dowa/d_memory.c	Sun Nov 09 06:25:16 2025 -0800
@@ -31,8 +31,8 @@
   if (!p_arena) return;
 
   if (p_arena->buffer)
-    free(p_arena->buffer);
-  free(p_arena);
+    Dowa_Free(p_arena->buffer);
+  Dowa_Free(p_arena);
 }
 
 void *Dowa_Arena_Copy(Dowa_PArena p_arena, const void *src, size_t size)
@@ -60,7 +60,7 @@
   p_hash_map->entries = calloc(capacity, sizeof(*p_hash_map->entries));
   if (p_hash_map->entries == NULL)
   {
-    free(p_hash_map);
+    Dowa_Free(p_hash_map);
     return NULL;
   }
   p_hash_map->capacity = capacity;
@@ -87,7 +87,7 @@
   memset(p_hash_map->entries, 0, capacity * sizeof *p_hash_map->entries);
   if (p_hash_map->entries == NULL)
   {
-    free(p_hash_map);
+    Dowa_Free(p_hash_map);
     return NULL;
   }
   p_hash_map->capacity = capacity;
@@ -116,15 +116,15 @@
         entry = p_hash_map->entries[idx];
         if (entry)
         {
-          free(entry->key);
-          free(entry->buffer);
-          free(entry);
+          Dowa_Free(entry->key);
+          Dowa_Free(entry->buffer);
+          Dowa_Free(entry);
         }
       }
     }
-    free(p_hash_map->entries);
+    Dowa_Free(p_hash_map->entries);
   }
-  free(p_hash_map);
+  Dowa_Free(p_hash_map);
 }
 
 int32 Dowa_HashMap_Get_Position(Dowa_PHashMap p_hash_map, const char *key)
@@ -169,17 +169,29 @@
   {
     if (strcmp(entry->key, key) == 0)
     {
-      if (!p_hash_map->p_arena && entry->buffer)
-        free(entry->buffer);
-      entry->buffer = value;
-      entry->capacity = value_size;
-      entry->type = type;
-      return 0; 
+      // Fails if it the key exists...
+      return -1; 
     }
-    prev = entry;
-    entry = entry->next;
   }
 
+  // Overriding doesn't really make sense? when copying over
+  // as we need to free it.
+  //
+  //while (entry)
+  //{
+  //  if (strcmp(entry->key, key) == 0)
+  //  {
+  //    if (!p_hash_map->p_arena && entry->buffer)
+  //      Dowa_Free(entry->buffer);
+  //    entry->buffer = value;
+  //    entry->capacity = value_size;
+  //    entry->type = type;
+  //    return 0; 
+  //  }
+  //  prev = entry;
+  //  entry = entry->next;
+  //}
+
   // New Key 
   entry = p_hash_map->p_arena ? 
     Dowa_Arena_Allocate(p_hash_map->p_arena, sizeof(Dowa_HashEntry)) :
@@ -217,7 +229,7 @@
     if (strcmp(entry->key, key) == 0)
     {
       if (!p_hash_map->p_arena && entry->buffer)
-        free(entry->buffer);
+        Dowa_Free(entry->buffer);
 
       entry->buffer = p_hash_map->p_arena ?
         Dowa_Arena_Allocate(p_hash_map->p_arena, value_size) :
@@ -274,9 +286,9 @@
   Dowa_PHashEntry entry = p_hash_map->entries[idx];
   if (entry && !(p_hash_map->p_arena))
   {
-    free(entry->key);
-    free(entry->buffer);
-    free(entry);
+    Dowa_Free(entry->key);
+    Dowa_Free(entry->buffer);
+    Dowa_Free(entry);
   }
   p_hash_map->entries[idx] = NULL;
   if (p_hash_map->current_capacity > 0)
@@ -368,14 +380,14 @@
       if (fread(buf, 1, size, f) != size)
       {
         perror("fread");
-        if (!p_hash_map->p_arena) free(buf);
+        if (!p_hash_map->p_arena) Dowa_Free(buf);
         fclose(f);
         continue;
       }
       fclose(f);
 
       Dowa_HashMap_Push_Value_With_Type(p_hash_map, entry->d_name, buf, size, DOWA_HASH_MAP_TYPE_STRING);
-      free(buf);  // Dowa_HashMap_PushValue made its own copy
+      Dowa_Free(buf);  // Dowa_HashMap_PushValue made its own copy
     }
     else if (S_ISDIR(st.st_mode))
     {