The R Project SVN R

Rev

Rev 27277 | Rev 35318 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27277 Rev 27285
Line 42... Line 42...
42
static void
42
static void
43
w_free(int m, int n)
43
w_free(int m, int n)
44
{
44
{
45
    int i, j;
45
    int i, j;
46
 
46
 
47
    if (m > n) {
-
 
48
	i = n; n = m; m = i;
-
 
49
    }
-
 
50
    m = imax2(m, WILCOX_MAX);
-
 
51
    n = imax2(n, WILCOX_MAX);
-
 
52
 
-
 
53
    for (i = m; i >= 0; i--) {
47
    for (i = m; i >= 0; i--) {
54
	for (j = n; j >= 0; j--) {
48
	for (j = n; j >= 0; j--) {
55
	    if (w[i][j] != 0)
49
	    if (w[i][j] != 0)
56
		free((void *) w[i][j]);
50
		free((void *) w[i][j]);
57
	}
51
	}
Line 65... Line 59...
65
w_init_maybe(int m, int n)
59
w_init_maybe(int m, int n)
66
{
60
{
67
    int i;
61
    int i;
68
 
62
 
69
    if (w) {
63
    if (w) {
70
/* this leaks memory --- according to Jean Coursol: */
-
 
71
	if (m > WILCOX_MAX || n > WILCOX_MAX)
-
 
72
	    w_free(WILCOX_MAX, WILCOX_MAX);
-
 
73
/* and he proposes -- but this segfaults for dwilcox(1,6,4);dwilcox(1,4,6)
-
 
74
*	if (m > allocated_m || n > allocated_n)
64
	if (m > allocated_m || n > allocated_n)
75
*	    w_free(allocated_m, allocated_n);
65
	    w_free(allocated_m, allocated_n); /* zeroes w */
76
*/
-
 
77
 
-
 
78
    }
66
    }
79
    else { /* initialize w[][] */
67
    if (!w) { /* initialize w[][] */
80
	allocated_m = m; allocated_n = n;
-
 
81
	if (m > n) {
68
	if (m > n) {
82
	    i = n; n = m; m = i;
69
	    i = n; n = m; m = i;
83
	}
70
	}
84
	m = imax2(m, WILCOX_MAX);
71
	m = imax2(m, WILCOX_MAX);
85
	n = imax2(n, WILCOX_MAX);
72
	n = imax2(n, WILCOX_MAX);
86
	w = (double ***) calloc(m + 1, sizeof(double **));
73
	w = (double ***) calloc(m + 1, sizeof(double **));
87
	if (!w)
74
	if (!w)
88
	    MATHLIB_ERROR("wilcox allocation error %d", 1);
75
	    MATHLIB_ERROR("wilcox allocation error %d", 1);
89
	for (i = 0; i <= m; i++) {
76
	for (i = 0; i <= m; i++) {
90
	    w[i] = (double **) calloc(n + 1, sizeof(double *));
77
	    w[i] = (double **) calloc(n + 1, sizeof(double *));
91
	    if (!w[i])
78
	    if (!w[i]) {
-
 
79
		/* first free all earlier allocations */
-
 
80
		w_free(i-1, n);
92
		MATHLIB_ERROR("wilcox allocation error %d", 2);
81
		MATHLIB_ERROR("wilcox allocation error %d", 2);
-
 
82
	    }
93
	}
83
	}
-
 
84
	allocated_m = m; allocated_n = n;
94
    }
85
    }
95
}
86
}
96
 
87
 
97
static void
88
static void
98
w_free_maybe(int m, int n)
89
w_free_maybe(int m, int n)