[AD] Patch to add an _al_strdup() function (4.3.10)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi all.

Please find attached some patches to fix a problem my memory tracker picked
up in 4.3.10.

There were some internal functions in src/readbmp.c, src/readfont.c and
src/readsmp.c that were calling the standard libc strdup() function to
duplicate a string, but were then calling the internal _AL_FREE() to free
it.  So when my memory tracker was in use it was getting triggered by the
calls to _AL_FREE() because the buffer wasn't in its memory list.  These
patches add a new internal _al_strdup() function that uses _AL_MALLOC() for
the memory allocation.

-- 
/-------------------------------------------------------------------\
[Hitman/Code HQ - 6502/z80/68000/604e/80x86/ARM coder - Amiga rulez!]
[VZ-200/VIC-20/MZ-700/c16/c64*10/c128*8/Plus-4/CPC464/CD32/500*2    ]
[600/1000/1200*2/A4000/SNES/N64/Dreamcast/Athlon 1100/AmigaOne      ]
[Assembly Language: The most fun you can have with your clothes on! ]
\-------------------------------------------------------------------/
--- include/allegro/internal/aintern.h	(revision 10970)
+++ include/allegro/internal/aintern.h	(working copy)
@@ -66,6 +66,7 @@
 AL_FUNC(void *, _al_malloc, (size_t size));
 AL_FUNC(void, _al_free, (void *mem));
 AL_FUNC(void *, _al_realloc, (void *mem, size_t size));
+AL_FUNC(char *, _al_strdup, (const char *string));
 
 
 
--- src/allegro.c	(revision 10970)
+++ src/allegro.c	(working copy)
@@ -711,6 +711,22 @@
 
 
 
+/* _al_strdup:
+ *  Wrapper for when a program needs to duplicate a string in a way that
+ *  uses any user overloaded memory allocation system in use.
+ */
+char *_al_strdup(const char *string)
+{
+   char *newstring = _AL_MALLOC(strlen(string) + 1);
+
+   if (newstring)
+      strcpy(newstring, string);
+
+   return newstring;
+}
+
+
+
 /* a simple system driver for platform-independent code */
 static int sys_none_init(void) { return 0; }
 static void sys_none_exit(void) { }
--- src/readbmp.c	(revision 10970)
+++ src/readbmp.c	(working copy)
@@ -57,7 +57,7 @@
    if (iter) {
       iter->load = load;
       iter->save = save;
-      iter->ext = strdup(aext);
+      iter->ext = _al_strdup(aext);
       iter->next = NULL;
    }
 }
--- src/readfont.c	(revision 10970)
+++ src/readfont.c	(working copy)
@@ -55,7 +55,7 @@
 
    if (iter) {
       iter->load = load;
-      iter->ext = strdup(aext);
+      iter->ext = _al_strdup(aext);
       iter->next = NULL;
    }
 }
--- src/readsmp.c	(revision 10970)
+++ src/readsmp.c	(working copy)
@@ -58,7 +58,7 @@
    if (iter) {
       iter->load = load;
       iter->save = save;
-      iter->ext = strdup(aext);
+      iter->ext = _al_strdup(aext);
       iter->next = NULL;
    }
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/