summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2003-11-08 15:33:13 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2003-11-08 15:33:13 (GMT)
commita89dda8cb1260f05f3e283ca80310b3090940341 (patch)
treef795625c9dd894d518b75a810c4d73a39f089f87 /src
parent677f6cc3d8d7000c19869f7c09e9a015606369b8 (diff)
downloadhdf5-a89dda8cb1260f05f3e283ca80310b3090940341.zip
hdf5-a89dda8cb1260f05f3e283ca80310b3090940341.tar.gz
hdf5-a89dda8cb1260f05f3e283ca80310b3090940341.tar.bz2
[svn-r7830] Purpose:
Bug fix & code cleanup Description: Allowing the library to call malloc with a size of 0 bytes causes problems for some users, so we check for allocations of 0 bytes and disallow them now. Cleaned up some code which could call malloc with 0 size. Changed some code calling HDmalloc directly to call H5MM_malloc(), which allows us to check for 0 sized allocations. Platforms tested: FreeBSD 4.9 (sleipnir) too minor to require h5committest
Diffstat (limited to 'src')
-rw-r--r--src/H5FP.c2
-rw-r--r--src/H5FPserver.c10
-rw-r--r--src/H5MM.c67
-rw-r--r--src/H5MMprivate.h11
-rw-r--r--src/H5config.h.in4
5 files changed, 79 insertions, 15 deletions
diff --git a/src/H5FP.c b/src/H5FP.c
index 60c73e3..5ca9a63 100644
--- a/src/H5FP.c
+++ b/src/H5FP.c
@@ -291,7 +291,7 @@ H5FP_read_metadata(char **mdata, int len, int from)
* There is metadata associated with this request. Get it as a
* string (requires another read).
*/
- if ((*mdata = (char *)HDmalloc((size_t)len + 1)) == NULL)
+ if ((*mdata = (char *)H5MM_malloc((size_t)len + 1)) == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "out of memory");
HDmemset(*mdata, 0, (size_t)len + 1);
diff --git a/src/H5FPserver.c b/src/H5FPserver.c
index 98c21c3..1e980c3 100644
--- a/src/H5FPserver.c
+++ b/src/H5FPserver.c
@@ -333,7 +333,7 @@ H5FP_new_object_lock(const unsigned char *oid, unsigned rank,
FUNC_ENTER_NOINIT(H5FP_new_object_lock);
assert(oid);
- if ((ret_value = (H5FP_object_lock *)HDmalloc(sizeof(H5FP_object_lock))) == NULL)
+ if ((ret_value = (H5FP_object_lock *)H5MM_malloc(sizeof(H5FP_object_lock))) == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "out of memory");
H5FP_COPY_OID(ret_value->oid, oid);
@@ -478,7 +478,7 @@ H5FP_new_file_mod_node(unsigned UNUSED rank, H5FD_mem_t mem_type,
FUNC_ENTER_NOINIT(H5FP_new_file_mod_node);
- if ((ret_value = (H5FP_mdata_mod *)HDmalloc(sizeof(H5FP_mdata_mod))) == NULL)
+ if ((ret_value = (H5FP_mdata_mod *)H5MM_malloc(sizeof(H5FP_mdata_mod))) == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "out of memory");
ret_value->mem_type = mem_type;
@@ -597,7 +597,7 @@ H5FP_new_file_info_node(unsigned file_id)
FUNC_ENTER_NOINIT(H5FP_new_file_info_node);
- if ((ret_value = (H5FP_file_info *)HDmalloc(sizeof(H5FP_file_info))) == NULL)
+ if ((ret_value = (H5FP_file_info *)H5MM_malloc(sizeof(H5FP_file_info))) == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "out of memory");
ret_value->file_id = file_id;
@@ -938,7 +938,7 @@ H5FP_sap_handle_lock_request(H5FP_request_t *req)
FUNC_ENTER_NOINIT(H5FP_sap_handle_lock_request);
- if ((oids = (struct lock_group *)HDmalloc(list_size *
+ if ((oids = (struct lock_group *)H5MM_malloc(list_size *
sizeof(struct lock_group))) == NULL) {
exit_state = H5FP_STATUS_OOM;
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "out of memory");
@@ -1141,7 +1141,7 @@ H5FP_sap_handle_release_lock_request(H5FP_request_t *req)
FUNC_ENTER_NOINIT(H5FP_sap_handle_release_lock_request);
- if ((oids = (struct release_group *)HDmalloc(list_size *
+ if ((oids = (struct release_group *)H5MM_malloc(list_size *
sizeof(struct release_group))) == NULL) {
exit_state = H5FP_STATUS_OOM;
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "out of memory");
diff --git a/src/H5MM.c b/src/H5MM.c
index 371f292..9701bb9 100644
--- a/src/H5MM.c
+++ b/src/H5MM.c
@@ -33,6 +33,73 @@
static int interface_initialize_g = 0;
#define INTERFACE_INIT NULL
+#ifndef NDEBUG
+
+/*-------------------------------------------------------------------------
+ * Function: H5MM_malloc
+ *
+ * Purpose: Just like the POSIX version of malloc(3). This routine
+ * specifically checks for allocations of 0 bytes and fails
+ * in that case. This routine is not called when NDEBUG is
+ * defined.
+ *
+ * Return: Success: Ptr to new memory
+ *
+ * Failure: NULL
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Nov 8 2003
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void *
+H5MM_malloc(size_t size)
+{
+ /* Use FUNC_ENTER_NOINIT here to avoid performance issues */
+ FUNC_ENTER_NOINIT(H5MM_malloc);
+
+ assert(size);
+
+ FUNC_LEAVE_NOAPI(HDmalloc(size));
+} /* end H5MM_malloc() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5MM_calloc
+ *
+ * Purpose: Similar to the POSIX version of calloc(3), except this routine
+ * just takes a 'size' parameter. This routine
+ * specifically checks for allocations of 0 bytes and fails
+ * in that case. This routine is not called when NDEBUG is
+ * defined.
+ *
+ * Return: Success: Ptr to new memory
+ *
+ * Failure: NULL
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Nov 8 2003
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void *
+H5MM_calloc(size_t size)
+{
+ /* Use FUNC_ENTER_NOINIT here to avoid performance issues */
+ FUNC_ENTER_NOINIT(H5MM_calloc);
+
+ assert(size);
+
+ FUNC_LEAVE_NOAPI(HDcalloc(1,size));
+} /* end H5MM_calloc() */
+#endif /* NDEBUG */
+
/*-------------------------------------------------------------------------
* Function: H5MM_realloc
diff --git a/src/H5MMprivate.h b/src/H5MMprivate.h
index 54dfbfb..9aadd36 100644
--- a/src/H5MMprivate.h
+++ b/src/H5MMprivate.h
@@ -32,18 +32,19 @@
/* Private headers needed by this file */
#include "H5private.h"
-#ifdef H5_MALLOC_WORKS
+#ifdef NDEBUG
#define H5MM_malloc(Z) HDmalloc(Z)
#define H5MM_calloc(Z) HDcalloc(1,Z)
-#else /* H5_MALLOC_WORKS */
-#define H5MM_malloc(Z) HDmalloc(MAX(1,Z))
-#define H5MM_calloc(Z) HDcalloc(1,MAX(1,Z))
-#endif /* H5_MALLOC_WORKS */
+#endif /* NDEBUG */
#define H5MM_free(Z) HDfree(Z)
/*
* Library prototypes...
*/
+#ifndef NDEBUG
+H5_DLL void *H5MM_malloc(size_t size);
+H5_DLL void *H5MM_calloc(size_t size);
+#endif /* NDEBUG */
H5_DLL void *H5MM_realloc(void *mem, size_t size);
H5_DLL char *H5MM_xstrdup(const char *s);
H5_DLL char *H5MM_strdup(const char *s);
diff --git a/src/H5config.h.in b/src/H5config.h.in
index 6e8e6d0..11c8e7b 100644
--- a/src/H5config.h.in
+++ b/src/H5config.h.in
@@ -340,10 +340,6 @@
/* Define if `__tm_gmtoff' is a member of `struct tm' */
#undef HAVE___TM_GMTOFF
-/* Define if your system's `malloc' function returns a valid pointer for
- 0-byte allocations. */
-#undef MALLOC_WORKS
-
/* Define if your system's `MPI_File_set_size' function works for files over
2GB. */
#undef MPI_FILE_SET_SIZE_BIG