Check result of my_malloc() in my_strdup()

master
Yevgen Muntyan 2007-03-12 00:39:56 -05:00
parent 5f7f9d83c3
commit 16397e50bc
2 changed files with 12 additions and 8 deletions

View File

@ -29,14 +29,15 @@
#define TIMESTAMP() (0) #define TIMESTAMP() (0)
#endif #endif
#undef DEBUG_MEMORY
#if 1 #ifndef DEBUG_MEMORY
static void static void
init_mem_stuff (void) init_mem_stuff (void)
{ {
} }
#else #else
#define ALIGN 4 #define ALIGN 8
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
static gpointer static gpointer
@ -67,7 +68,8 @@ my_strdup (const char *s)
if (s) if (s)
{ {
char *new_s = my_malloc (strlen (s) + 1); char *new_s = my_malloc (strlen (s) + 1);
strcpy (new_s, s); if (new_s)
strcpy (new_s, s);
return new_s; return new_s;
} }
else else
@ -93,7 +95,7 @@ init_mem_stuff (void)
NULL, NULL, NULL NULL, NULL, NULL
}; };
if (0) if (1)
{ {
g_mem_set_vtable (&mem_table); g_mem_set_vtable (&mem_table);
g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE); g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE);

View File

@ -28,14 +28,15 @@
#define TIMESTAMP() (0) #define TIMESTAMP() (0)
#endif #endif
#undef DEBUG_MEMORY
#if 1 #ifndef DEBUG_MEMORY
static void static void
init_mem_stuff (void) init_mem_stuff (void)
{ {
} }
#else #else
#define ALIGN 4 #define ALIGN 8
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
static gpointer static gpointer
@ -66,7 +67,8 @@ my_strdup (const char *s)
if (s) if (s)
{ {
char *new_s = my_malloc (strlen (s) + 1); char *new_s = my_malloc (strlen (s) + 1);
strcpy (new_s, s); if (new_s)
strcpy (new_s, s);
return new_s; return new_s;
} }
else else
@ -92,7 +94,7 @@ init_mem_stuff (void)
NULL, NULL, NULL NULL, NULL, NULL
}; };
if (0) if (1)
{ {
g_mem_set_vtable (&mem_table); g_mem_set_vtable (&mem_table);
g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE); g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE);