Skip to content

Commit ebac866

Browse files
TheAssembler1github-actions[bot]jeanbez
authored
Use PDC_malloc, PDC_free, PDC_calloc, and PDC_realloc (#260)
* checkpoint * replace free with PDC_free and calloc with PDC_calloc * Committing clang-format changes * fix more mallocs to PDC_malloc * more PDC_free fixes * Committing clang-format changes * Update ubuntu-cache.yml * remove eno1 * fix realloc * Committing clang-format changes * Update ubuntu-no-cache.yaml * Fix several bugs with error checking with object dim allocation * Committing clang-format changes * fix bug * Committing clang-format changes * Update ubuntu-no-cache.yaml * Update ubuntu-cache.yml * Set default value of ndim to 1 in PDCprop_create when using PDC_OBJ_CREATE * Committing clang-format changes * Malloc when defaulting to ndim size 1. Only free hostname when we PDC_malloc the memory because pointers returned by getenv are not malloced and could point to static memory. * Committing clang-format changes * Update README.md minor change to trigger the pipeline --------- Co-authored-by: github-actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jean Luca Bez <[email protected]> Co-authored-by: Jean Luca Bez <[email protected]>
1 parent 54383bf commit ebac866

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1460
-2337
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Proactive Data Containers (PDC) software provides an object-focused data managem
1515

1616
Full documentation of PDC with installation instructions, code examples for using PDC API, and research publications are available at [pdc.readthedocs.io](https://pdc.readthedocs.io)
1717

18-
More information and publications on PDC is available at https://sdm.lbl.gov/pdc
18+
More information and publications on PDC are available at https://sdm.lbl.gov/pdc
1919

2020
If you use PDC in your research, please use the following citations:
2121

src/api/pdc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ PDC_class__close(struct _pdc_class *p)
130130
PDC_timing_finalize();
131131
#endif
132132

133-
free(p->name);
134-
p = (struct _pdc_class *)(intptr_t)PDC_free(p);
133+
p->name = (char *)PDC_free(p->name);
134+
p = (struct _pdc_class *)(intptr_t)PDC_free(p);
135135

136136
FUNC_LEAVE(ret_value);
137137
}

src/api/pdc_analysis/pdc_analysis.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ iterator_init(pdcid_t objectId, pdcid_t reg_id, int blocks, struct _pdc_iterator
101101
}
102102
}
103103
iter->totalElements = 1;
104-
if ((iter->srcDims = (size_t *)calloc(obj_prop_ptr->obj_prop_pub->ndim, sizeof(size_t))) != NULL) {
104+
if ((iter->srcDims = (size_t *)PDC_calloc(obj_prop_ptr->obj_prop_pub->ndim, sizeof(size_t))) !=
105+
NULL) {
105106
iter->ndim = obj_prop_ptr->obj_prop_pub->ndim;
106107
for (i = 0; i < iter->ndim; i++) {
107108
iter->srcDims[i] = (size_t)obj_prop_ptr->obj_prop_pub->dims[i];
@@ -336,13 +337,13 @@ PDC_get_argv0_()
336337
procpath = strdup(fullPath);
337338
shellcmd = fopen(procpath, "r");
338339
if (shellcmd == NULL) {
339-
free(procpath);
340+
procpath = (char *)PDC_free(procpath);
340341
PGOTO_ERROR(NULL, "fopen failed!");
341342
}
342343
else {
343344
cmdLength = fread(fullPath, 1, sizeof(fullPath), shellcmd);
344345
if (procpath)
345-
free(procpath);
346+
procpath = (char *)PDC_free(procpath);
346347
if (cmdLength > 0) {
347348
_argv0 = strdup(fullPath);
348349
/* truncate the cmdline if any whitespace (space or tab) */
@@ -366,7 +367,7 @@ PDC_get_argv0_()
366367
/* Get rid of the copy (strdup) of fullPath now in _argv0.
367368
* and replace it with the next (modified/fully_qualified?) version.
368369
*/
369-
free(_argv0);
370+
_argv0 = (char *)PDC_free(_argv0);
370371
_argv0 = next;
371372
}
372373
}
@@ -460,7 +461,7 @@ PDCobj_analysis_register(char *func, pdcid_t iterIn, pdcid_t iterOut)
460461
thisFtn->ftnPtr = (int (*)())ftnPtr;
461462
thisFtn->n_args = 2;
462463
/* Allocate for iterator ids and region ids */
463-
if ((thisFtn->object_id = (pdcid_t *)calloc(4, sizeof(pdcid_t))) != NULL) {
464+
if ((thisFtn->object_id = (pdcid_t *)PDC_calloc(4, sizeof(pdcid_t))) != NULL) {
464465
thisFtn->object_id[0] = iterIn;
465466
thisFtn->object_id[1] = iterOut;
466467
}
@@ -497,11 +498,11 @@ PDCobj_analysis_register(char *func, pdcid_t iterIn, pdcid_t iterOut)
497498

498499
done:
499500
if (applicationDir)
500-
free(applicationDir);
501+
applicationDir = (char *)PDC_free(applicationDir);
501502
if (userdefinedftn)
502-
free(userdefinedftn);
503+
userdefinedftn = (char *)PDC_free(userdefinedftn);
503504
if (loadpath)
504-
free(loadpath);
505+
loadpath = (char *)PDC_free(loadpath);
505506

506507
fflush(stdout);
507508
FUNC_LEAVE(ret_value);
@@ -556,7 +557,7 @@ PDCobj_data_getNextBlock(pdcid_t iter, void **nextBlock, size_t *dims)
556557
if (thisIter->srcStart == NULL) {
557558
if (execution_locus == SERVER_MEMORY) {
558559
if ((thisIter->srcNext = PDC_Server_get_region_data_ptr(thisIter->objectId)) == NULL)
559-
thisIter->srcNext = malloc(thisIter->totalElements * thisIter->element_size);
560+
thisIter->srcNext = PDC_malloc(thisIter->totalElements * thisIter->element_size);
560561
if ((thisIter->srcStart = thisIter->srcNext) == NULL)
561562
PGOTO_ERROR(0, "==PDC_ANALYSIS_SERVER: Unable to allocate iterator storage");
562563

src/api/pdc_analysis/pdc_analysis_and_transforms_connect.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PDC_Client_send_iter_recv_id(pdcid_t iter_id, pdcid_t *meta_id)
6363
hg_atomic_init32(atomic_work_todo_g, 0);
6464
}
6565

66-
my_rpc_state_p = (struct _pdc_my_rpc_state *)calloc(1, sizeof(struct _pdc_my_rpc_state));
66+
my_rpc_state_p = (struct _pdc_my_rpc_state *)PDC_calloc(1, sizeof(struct _pdc_my_rpc_state));
6767
if (my_rpc_state_p == NULL)
6868
PGOTO_ERROR(FAIL, "PDC_Client_send_iter_recv_id(): Could not allocate my_rpc_state");
6969

@@ -130,7 +130,7 @@ PDC_Client_send_iter_recv_id(pdcid_t iter_id, pdcid_t *meta_id)
130130
done:
131131
fflush(stdout);
132132
HG_Destroy(my_rpc_state_p->handle);
133-
free(my_rpc_state_p);
133+
my_rpc_state_p = (struct _pdc_my_rpc_state *)PDC_free(my_rpc_state_p);
134134

135135
FUNC_LEAVE(ret_value);
136136
}
@@ -183,7 +183,7 @@ PDC_Client_register_obj_analysis(struct _pdc_region_analysis_ftn_info *thisFtn,
183183
hg_atomic_init32(atomic_work_todo_g, 0);
184184
}
185185

186-
my_rpc_state_p = (struct _pdc_my_rpc_state *)calloc(1, sizeof(struct _pdc_my_rpc_state));
186+
my_rpc_state_p = (struct _pdc_my_rpc_state *)PDC_calloc(1, sizeof(struct _pdc_my_rpc_state));
187187
if (my_rpc_state_p == NULL)
188188
PGOTO_ERROR(FAIL, "PDC_Client_register_obj_analysis(): Could not allocate my_rpc_state");
189189

@@ -250,7 +250,7 @@ PDC_Client_register_obj_analysis(struct _pdc_region_analysis_ftn_info *thisFtn,
250250
done:
251251
fflush(stdout);
252252
HG_Destroy(my_rpc_state_p->handle);
253-
free(my_rpc_state_p);
253+
my_rpc_state_p = (struct _pdc_my_rpc_state *)PDC_free(my_rpc_state_p);
254254

255255
FUNC_LEAVE(ret_value);
256256
}
@@ -301,7 +301,7 @@ PDC_Client_register_region_transform(const char *func, const char *loadpath,
301301
hg_atomic_init32(atomic_work_todo_g, 0);
302302
}
303303

304-
my_rpc_state_p = (struct _pdc_my_rpc_state *)calloc(1, sizeof(struct _pdc_my_rpc_state));
304+
my_rpc_state_p = (struct _pdc_my_rpc_state *)PDC_calloc(1, sizeof(struct _pdc_my_rpc_state));
305305
if (my_rpc_state_p == NULL)
306306
PGOTO_ERROR(FAIL, "Could not allocate my_rpc_state");
307307

@@ -345,7 +345,7 @@ PDC_Client_register_region_transform(const char *func, const char *loadpath,
345345
if (object_info)
346346
PDC_free_obj_info(object_info);
347347
HG_Destroy(my_rpc_state_p->handle);
348-
free(my_rpc_state_p);
348+
my_rpc_state_p = (struct _pdc_my_rpc_state *)PDC_free(my_rpc_state_p);
349349

350350
FUNC_LEAVE(ret_value);
351351
}

src/api/pdc_analysis/pdc_analysis_common.c

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "pdc_analysis_and_transforms_common.h"
3535
#include "pdc_client_server_common.h"
3636
#include "pdc_analysis_pkg.h"
37+
#include "pdc_malloc.h"
3738
#include "pdc_region.h"
3839
#include "pdc_server_analysis.h"
3940
#include "pdc_logger.h"
@@ -90,7 +91,7 @@ pdc_analysis_registry_init_(size_t newSize)
9091
FUNC_ENTER(NULL);
9192

9293
if (pdc_region_analysis_registry == NULL) {
93-
new_registry = (struct _pdc_region_analysis_ftn_info **)calloc(sizeof(void *), newSize);
94+
new_registry = (struct _pdc_region_analysis_ftn_info **)PDC_calloc(sizeof(void *), newSize);
9495
if (new_registry) {
9596
hg_atomic_init32(&registered_analysis_ftn_count_g, 0);
9697
pdc_region_analysis_registry = new_registry;
@@ -99,11 +100,12 @@ pdc_analysis_registry_init_(size_t newSize)
99100
}
100101
}
101102
else if (newSize > analysis_registry_size) {
102-
new_registry = (struct _pdc_region_analysis_ftn_info **)calloc(sizeof(void *), newSize);
103+
new_registry = (struct _pdc_region_analysis_ftn_info **)PDC_calloc(sizeof(void *), newSize);
103104
if (new_registry) {
104105
size_t copysize = analysis_registry_size * sizeof(void *);
105106
memcpy(new_registry, pdc_region_analysis_registry, copysize);
106-
free(pdc_region_analysis_registry);
107+
pdc_region_analysis_registry =
108+
(struct _pdc_region_analysis_ftn_info **)PDC_free(pdc_region_analysis_registry);
107109
pdc_region_analysis_registry = new_registry;
108110
analysis_registry_size = newSize;
109111
PGOTO_DONE(newSize);
@@ -125,7 +127,7 @@ pdc_transform_registry_init_(size_t newSize)
125127
FUNC_ENTER(NULL);
126128

127129
if (pdc_region_transform_registry == NULL) {
128-
new_registry = (struct _pdc_region_transform_ftn_info **)calloc(sizeof(void *), newSize);
130+
new_registry = (struct _pdc_region_transform_ftn_info **)PDC_calloc(sizeof(void *), newSize);
129131
if (new_registry) {
130132
hg_atomic_init32(&registered_transform_ftn_count_g, 0);
131133
pdc_region_transform_registry = new_registry;
@@ -134,11 +136,12 @@ pdc_transform_registry_init_(size_t newSize)
134136
}
135137
}
136138
else if (newSize > transform_registry_size) {
137-
new_registry = (struct _pdc_region_transform_ftn_info **)calloc(sizeof(void *), newSize);
139+
new_registry = (struct _pdc_region_transform_ftn_info **)PDC_calloc(sizeof(void *), newSize);
138140
if (new_registry) {
139141
copysize = transform_registry_size * sizeof(void *);
140142
memcpy(new_registry, pdc_region_transform_registry, copysize);
141-
free(pdc_region_transform_registry);
143+
pdc_region_transform_registry =
144+
(struct _pdc_region_transform_ftn_info **)PDC_free(pdc_region_transform_registry);
142145
pdc_region_transform_registry = new_registry;
143146
transform_registry_size = newSize;
144147
PGOTO_DONE(newSize);
@@ -161,11 +164,12 @@ pdc_analysis_registry_finalize_()
161164
if ((pdc_region_analysis_registry != NULL) && (analysis_registry_size > 0)) {
162165
while (hg_atomic_get32(&i) > 0) {
163166
if (pdc_region_analysis_registry[i - 1])
164-
free(pdc_region_analysis_registry[i - 1]);
165-
pdc_region_analysis_registry[i - 1] = NULL;
167+
pdc_region_analysis_registry[i - 1] =
168+
(struct _pdc_region_analysis_ftn_info *)PDC_free(pdc_region_analysis_registry[i - 1]);
166169
hg_atomic_decr32(&i);
167170
}
168-
free(pdc_region_analysis_registry);
171+
pdc_region_analysis_registry =
172+
(struct _pdc_region_analysis_ftn_info **)PDC_free(pdc_region_analysis_registry);
169173
analysis_registry_size = 0;
170174
hg_atomic_init32(&registered_analysis_ftn_count_g, 0);
171175
}
@@ -250,12 +254,12 @@ PDCiter_get_nextId(void)
250254
FUNC_ENTER(NULL);
251255

252256
if (PDC_Block_iterator_cache == NULL) {
253-
PDC_Block_iterator_cache =
254-
(struct _pdc_iterator_info *)calloc(iterator_cache_entries, sizeof(struct _pdc_iterator_info));
257+
PDC_Block_iterator_cache = (struct _pdc_iterator_info *)PDC_calloc(iterator_cache_entries,
258+
sizeof(struct _pdc_iterator_info));
255259
if (PDC_Block_iterator_cache == NULL)
256260
PGOTO_ERROR(-1, "calloc failed");
257261

258-
i_cache_freed = (int *)calloc(iterator_cache_entries, sizeof(int));
262+
i_cache_freed = (int *)PDC_calloc(iterator_cache_entries, sizeof(int));
259263
/* Index 0 is NOT-USED other than to indicate an empty iterator */
260264
hg_atomic_init32(&i_cache_index, 1);
261265
hg_atomic_init32(&i_free_index, 0);
@@ -274,15 +278,15 @@ PDCiter_get_nextId(void)
274278
/* Realloc the cache and free list */
275279
previous_i_cache_freed = i_cache_freed;
276280
previous_state = PDC_Block_iterator_cache;
277-
PDC_Block_iterator_cache = (struct _pdc_iterator_info *)calloc(iterator_cache_entries * 2,
278-
sizeof(struct _pdc_iterator_info));
281+
PDC_Block_iterator_cache = (struct _pdc_iterator_info *)PDC_calloc(iterator_cache_entries * 2,
282+
sizeof(struct _pdc_iterator_info));
279283
memcpy(PDC_Block_iterator_cache, previous_state,
280284
iterator_cache_entries * sizeof(struct _pdc_iterator_info));
281-
i_cache_freed = (int *)calloc(iterator_cache_entries * 2, sizeof(int));
285+
i_cache_freed = (int *)PDC_calloc(iterator_cache_entries * 2, sizeof(int));
282286
memcpy(i_cache_freed, previous_i_cache_freed, iterator_cache_entries * sizeof(int));
283287
iterator_cache_entries *= 2;
284-
free(previous_i_cache_freed);
285-
free(previous_state);
288+
previous_i_cache_freed = (int *)PDC_free(previous_i_cache_freed);
289+
previous_state = (struct _pdc_iterator_info *)PDC_free(previous_state);
286290
}
287291

288292
ret_value = nextId;
@@ -492,11 +496,11 @@ HG_TEST_RPC_CB(analysis_ftn, handle)
492496
* Otherwise, go ahead and register...
493497
*/
494498
if (nulliter_count < 2) {
495-
if ((thisFtn = (struct _pdc_region_analysis_ftn_info *)calloc(
499+
if ((thisFtn = (struct _pdc_region_analysis_ftn_info *)PDC_calloc(
496500
sizeof(struct _pdc_region_analysis_ftn_info), 1)) != NULL) {
497501
thisFtn->ftnPtr = (int (*)())ftnPtr;
498502
thisFtn->n_args = 2;
499-
thisFtn->object_id = (pdcid_t *)calloc(2, sizeof(pdcid_t));
503+
thisFtn->object_id = (pdcid_t *)PDC_calloc(2, sizeof(pdcid_t));
500504
registrationId = PDC_add_analysis_ptr_to_registry_(thisFtn);
501505
out.remote_ftn_id = registrationId;
502506
}
@@ -601,10 +605,11 @@ PDC_free_analysis_registry()
601605

602606
if (pdc_region_analysis_registry && (registered_analysis_ftn_count_g > 0)) {
603607
for (index = 0; index < registered_analysis_ftn_count_g; index++) {
604-
free(pdc_region_analysis_registry[index]);
608+
pdc_region_analysis_registry[index] =
609+
(struct _pdc_region_analysis_ftn_info *)PDC_free(pdc_region_analysis_registry[index]);
605610
}
606-
free(pdc_region_analysis_registry);
607-
pdc_region_analysis_registry = NULL;
611+
pdc_region_analysis_registry =
612+
(struct _pdc_region_analysis_ftn_info **)PDC_free(pdc_region_analysis_registry);
608613
}
609614

610615
FUNC_LEAVE_VOID;
@@ -619,10 +624,11 @@ PDC_free_transform_registry()
619624

620625
if (pdc_region_transform_registry && (registered_transform_ftn_count_g > 0)) {
621626
for (index = 0; index < registered_transform_ftn_count_g; index++) {
622-
free(pdc_region_transform_registry[index]);
627+
pdc_region_transform_registry[index] =
628+
(struct _pdc_region_transform_ftn_info *)PDC_free(pdc_region_transform_registry[index]);
623629
}
624-
free(pdc_region_transform_registry);
625-
pdc_region_transform_registry = NULL;
630+
pdc_region_transform_registry =
631+
(struct _pdc_region_transform_ftn_info **)PDC_free(pdc_region_transform_registry);
626632
}
627633

628634
FUNC_LEAVE_VOID;
@@ -635,8 +641,7 @@ PDC_free_iterator_cache()
635641
FUNC_ENTER(NULL);
636642

637643
if (PDC_Block_iterator_cache != NULL)
638-
free(PDC_Block_iterator_cache);
639-
PDC_Block_iterator_cache = NULL;
644+
PDC_Block_iterator_cache = (struct _pdc_iterator_info *)PDC_free(PDC_Block_iterator_cache);
640645

641646
FUNC_LEAVE_VOID;
642647
}

src/api/pdc_analysis/pdc_hist_pkg.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdio.h>
33
#include <stdlib.h>
44
#include "pdc_logger.h"
5+
#include "pdc_malloc.h"
56

67
#define MACRO_SAMPLE_MIN_MAX(TYPE, n, data, sample_pct, min, max) \
78
({ \
@@ -123,11 +124,11 @@ PDC_create_hist(pdc_var_type_t dtype, int nbin, double min, double max)
123124
bin_incr = floor_power_of_2((max - min) / (nbin - 2)); // Excluding first and last bin (open ended)
124125
nbin = ceil((max - min) / bin_incr);
125126

126-
hist = (pdc_histogram_t *)malloc(sizeof(pdc_histogram_t));
127+
hist = (pdc_histogram_t *)PDC_malloc(sizeof(pdc_histogram_t));
127128
hist->incr = bin_incr;
128129
hist->dtype = dtype;
129-
hist->range = (double *)calloc(sizeof(double), nbin * 2);
130-
hist->bin = (uint64_t *)calloc(sizeof(uint64_t), nbin);
130+
hist->range = (double *)PDC_calloc(sizeof(double), nbin * 2);
131+
hist->bin = (uint64_t *)PDC_calloc(sizeof(uint64_t), nbin);
131132
hist->nbin = nbin;
132133

133134
min_bin = floor(min);
@@ -292,9 +293,9 @@ PDC_free_hist(pdc_histogram_t *hist)
292293
if (NULL == hist)
293294
PGOTO_DONE_VOID;
294295

295-
free(hist->range);
296-
free(hist->bin);
297-
free(hist);
296+
hist->range = (double *)PDC_free(hist->range);
297+
hist->bin = (uint64_t *)PDC_free(hist->bin);
298+
hist = (pdc_histogram_t *)PDC_free(hist);
298299

299300
done:
300301
fflush(stdout);
@@ -337,11 +338,11 @@ PDC_dup_hist(pdc_histogram_t *hist)
337338
PGOTO_DONE(NULL);
338339

339340
nbin = hist->nbin;
340-
res = (pdc_histogram_t *)malloc(sizeof(pdc_histogram_t));
341+
res = (pdc_histogram_t *)PDC_malloc(sizeof(pdc_histogram_t));
341342
res->dtype = hist->dtype;
342343
res->nbin = nbin;
343-
res->range = (double *)calloc(sizeof(double), nbin * 2);
344-
res->bin = (uint64_t *)calloc(sizeof(uint64_t), nbin);
344+
res->range = (double *)PDC_calloc(sizeof(double), nbin * 2);
345+
res->bin = (uint64_t *)PDC_calloc(sizeof(uint64_t), nbin);
345346
res->incr = hist->incr;
346347

347348
memcpy(res->range, hist->range, sizeof(double) * nbin * 2);
@@ -434,10 +435,10 @@ PDC_copy_hist(pdc_histogram_t *to, pdc_histogram_t *from)
434435
to->incr = from->incr;
435436
to->dtype = from->dtype;
436437
if (NULL == to->range)
437-
to->range = (double *)calloc(sizeof(double), nbin * 2);
438+
to->range = (double *)PDC_calloc(sizeof(double), nbin * 2);
438439
memcpy(to->range, from->range, sizeof(double) * nbin * 2);
439440
if (NULL == to->bin)
440-
to->bin = (uint64_t *)calloc(sizeof(uint64_t), nbin);
441+
to->bin = (uint64_t *)PDC_calloc(sizeof(uint64_t), nbin);
441442
memcpy(to->bin, from->bin, sizeof(uint64_t) * nbin);
442443
to->nbin = from->nbin;
443444

0 commit comments

Comments
 (0)