1
/* ========================================================================== */
2
/* === UMF_malloc =========================================================== */
3
/* ========================================================================== */
5
/* -------------------------------------------------------------------------- */
6
/* UMFPACK Version 4.1 (Apr. 30, 2003), Copyright (c) 2003 by Timothy A. */
7
/* Davis. All Rights Reserved. See ../README for License. */
8
/* email: davis@cise.ufl.edu CISE Department, Univ. of Florida. */
9
/* web: http://www.cise.ufl.edu/research/sparse/umfpack */
10
/* -------------------------------------------------------------------------- */
13
Allocate a block of n objects, each of a given size. This routine does not
14
handle the case when the size is 1 (allocating char's) because of potential
15
integer overflow. UMFPACK never does that.
16
Also maintains the UMFPACK malloc count.
19
#include "umf_internal.h"
21
#if defined (UMF_MALLOC_COUNT) || !defined (NDEBUG)
24
UMF_malloc_count is a count of the objects malloc'd by UMFPACK. If you
25
suspect a memory leak in your program (caused by not properly destroying
26
the Symbolic and Numeric objects) then compile with -DUMF_MALLOC_COUNT and
27
check value of UMF_malloc_count. By default, UMF_MALLOC_COUNT is not
28
defined, and thus UMFPACK has no global variables.
31
GLOBAL Int UMF_malloc_count = 0 ;
36
/* For exhaustive statement coverage testing only! */
37
GLOBAL Int umf_fail, umf_fail_lo, umf_fail_hi ;
38
GLOBAL Int umf_realloc_fail, umf_realloc_lo, umf_realloc_hi ;
41
GLOBAL void *UMF_malloc
51
/* For exhaustive statement coverage testing only! */
52
/* Pretend to fail, to test out-of-memory conditions. */
54
if (umf_fail <= umf_fail_hi && umf_fail >= umf_fail_lo)
56
DEBUG0 (("umf_malloc: Pretend to fail %d %d %d\n",
57
umf_fail, umf_fail_hi, umf_fail_lo)) ;
58
return ((void *) NULL) ;
62
DEBUG0 (("UMF_malloc: ")) ;
64
/* make sure that we allocate something */
65
n_objects = MAX (1, n_objects) ;
67
size = (size_t) n_objects ;
68
ASSERT (size_of_object > 1) ;
69
if (size > Int_MAX / size_of_object)
71
/* object is too big for integer pointer arithmetic */
72
return ((void *) NULL) ;
74
size *= size_of_object ;
76
/* see umf_config.h for the memory allocator selection */
79
DEBUG0 ((ID"\n", (Int) p)) ;
81
#if defined (UMF_MALLOC_COUNT) || !defined (NDEBUG)
84
/* One more object has been malloc'ed. Keep track of the count. */
85
/* (purely for sanity checks). */
87
DEBUG0 ((" successful, new malloc count: "ID"\n", UMF_malloc_count)) ;