Skip to content

Commit 2d25f58

Browse files
committed
Use std::vector instead of malloc()/free().
1 parent b6f94d4 commit 2d25f58

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/libnml/cms/cms_xup.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern "C" {
1919
#include <stdlib.h> /* malloc(), free() */
2020
}
2121

22+
#include <vector>
2223
#include "cms.hh" /* class CMS */
2324
#include "cms_xup.hh" /* class CMS_XDR_UPDATER */
2425
#include "rcs_print.hh" /* rcs_print_error() */
@@ -656,23 +657,20 @@ CMS_STATUS CMS_XDR_UPDATER::update(long double *x, unsigned int len)
656657
return (CMS_UPDATE_ERROR);
657658
}
658659

659-
unsigned int i;
660-
double *y;
661-
y = (double *) malloc(sizeof(double) * len);
662-
for (i = 0; i < len; i++) {
663-
y[i] = (double) x[i];
660+
std::vector<double> y(len);
661+
for(unsigned i = 0; i < len; i++) {
662+
y[i] = (double) x[i];
664663
}
665664

666-
if (xdr_vector(current_stream, (char *) y, len, sizeof(double),
665+
if (xdr_vector(current_stream, (char *)y.data(), len, sizeof(double),
667666
(xdrproc_t) xdr_double) != TRUE) {
668667
rcs_print_error
669668
("CMS_XDR_UPDATER: xdr_vector(... xdr_double) failed.\n");
670669
return (status = CMS_UPDATE_ERROR);
671670
}
672671

673-
for (i = 0; i < len; i++) {
672+
for(unsigned i = 0; i < len; i++) {
674673
x[i] = (long double) y[i];
675674
}
676-
free(y);
677675
return (status);
678676
}

0 commit comments

Comments
 (0)