diff --git a/src/algs/cdirect/cdirect.c b/src/algs/cdirect/cdirect.c index 1cfd78f0..dbb1f2a8 100644 --- a/src/algs/cdirect/cdirect.c +++ b/src/algs/cdirect/cdirect.c @@ -579,7 +579,7 @@ nlopt_result cdirect(int n, nlopt_func f, void *f_data, int i; d.f = f; d.f_data = f_data; d.lb = lb; d.ub = ub; - d.x = (double *) malloc(sizeof(double) * n * (stop->xtol_abs ? 4 : 3)); + d.x = (double *) calloc(n * (stop->xtol_abs ? 4 : 3), sizeof(double)); if (!d.x) return NLOPT_OUT_OF_MEMORY; for (i = 0; i < n; ++i) { diff --git a/src/algs/cdirect/hybrid.c b/src/algs/cdirect/hybrid.c index 4ddb5a08..4af08d4f 100644 --- a/src/algs/cdirect/hybrid.c +++ b/src/algs/cdirect/hybrid.c @@ -320,7 +320,7 @@ nlopt_result cdirect_hybrid(int n, nlopt_func f, void *f_data, int i; d.f = f; d.f_data = f_data; d.lb = lb; d.ub = ub; - d.x = (double *) malloc(sizeof(double) * n * (stop->xtol_abs ? 4 : 3)); + d.x = (double *) calloc(n * (stop->xtol_abs ? 4 : 3), sizeof(double)); if (!d.x) return NLOPT_OUT_OF_MEMORY; for (i = 0; i < n; ++i) {