Skip to content

Commit f2609ca

Browse files
Merge pull request #382 from Treece-Burgess/05-16-2025-cmp-memory-allocation
Various Components: Avoid Mixed Memory Allocation
2 parents fd6c5e6 + 8837701 commit f2609ca

File tree

11 files changed

+149
-148
lines changed

11 files changed

+149
-148
lines changed

src/components/coretemp/linux-coretemp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ insert_in_list(char *name, char *units,
7272
/* Because this is a function, it is possible */
7373
/* we are called with root!=NULL but no last */
7474
/* so add this to keep coverity happy */
75-
free(temp);
75+
papi_free(temp);
7676
PAPIERROR("This shouldn't be possible\n");
7777

7878
return PAPI_ECMP;

src/components/cuda/cupti_profiler.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static int get_counter_availability(cuptip_gpu_state_t *gpu_ctl)
460460

461461
// Allocate the necessary memory for data
462462
gpu_ctl->counterAvailabilityImage.size = getCounterAvailabilityParams.counterAvailabilityImageSize;
463-
gpu_ctl->counterAvailabilityImage.data = (uint8_t *) papi_malloc(gpu_ctl->counterAvailabilityImage.size);
463+
gpu_ctl->counterAvailabilityImage.data = (uint8_t *) malloc(gpu_ctl->counterAvailabilityImage.size);
464464
if (gpu_ctl->counterAvailabilityImage.data == NULL) {
465465
ERRDBG("Failed to allocate memory for counterAvailabilityImage.data.\n");
466466
return PAPI_ENOMEM;
@@ -484,23 +484,23 @@ void free_and_reset_configuration_images(cuptip_gpu_state_t *gpu_ctl)
484484
COMPDBG("Entering.\n");
485485
// Note that you can find the memory allocation for the below variables
486486
// in cuptip_ctx_start as of April 21st, 2025
487-
papi_free(gpu_ctl->configImage.data);
487+
free(gpu_ctl->configImage.data);
488488
gpu_ctl->configImage.data = NULL;
489489
gpu_ctl->configImage.size = 0;
490490

491-
papi_free(gpu_ctl->counterDataPrefixImage.data);
491+
free(gpu_ctl->counterDataPrefixImage.data);
492492
gpu_ctl->counterDataPrefixImage.data = NULL;
493493
gpu_ctl->counterDataPrefixImage.size = 0;
494494

495-
papi_free(gpu_ctl->counterDataScratchBuffer.data);
495+
free(gpu_ctl->counterDataScratchBuffer.data);
496496
gpu_ctl->counterDataScratchBuffer.data = NULL;
497497
gpu_ctl->counterDataScratchBuffer.size = 0;
498498

499-
papi_free(gpu_ctl->counterDataImage.data);
499+
free(gpu_ctl->counterDataImage.data);
500500
gpu_ctl->counterDataImage.data = NULL;
501501
gpu_ctl->counterDataImage.size = 0;
502502

503-
papi_free(gpu_ctl->counterAvailabilityImage.data);
503+
free(gpu_ctl->counterAvailabilityImage.data);
504504
gpu_ctl->counterAvailabilityImage.data = NULL;
505505
gpu_ctl->counterAvailabilityImage.size = 0;
506506
}
@@ -534,7 +534,7 @@ static int init_main_htable(void)
534534
val *= base;
535535
}
536536

537-
cuptiu_table_p = (cuptiu_event_table_t *) papi_malloc(sizeof(cuptiu_event_table_t));
537+
cuptiu_table_p = (cuptiu_event_table_t *) malloc(sizeof(cuptiu_event_table_t));
538538
if (cuptiu_table_p == NULL) {
539539
ERRDBG("Failed to allocate memory for cuptiu_table_p.\n");
540540
return PAPI_ENOMEM;
@@ -543,19 +543,19 @@ static int init_main_htable(void)
543543
cuptiu_table_p->count = 0;
544544
cuptiu_table_p->event_stats_count = 0;
545545

546-
cuptiu_table_p->events = (cuptiu_event_t *) papi_calloc(val, sizeof(cuptiu_event_t));
546+
cuptiu_table_p->events = (cuptiu_event_t *) calloc(val, sizeof(cuptiu_event_t));
547547
if (cuptiu_table_p->events == NULL) {
548548
ERRDBG("Failed to allocate memory for cuptiu_table_p->events.\n");
549549
return PAPI_ENOMEM;
550550
}
551551

552-
cuptiu_table_p->event_stats = (StringVector *) papi_calloc(val, sizeof(StringVector));
552+
cuptiu_table_p->event_stats = (StringVector *) calloc(val, sizeof(StringVector));
553553
if (cuptiu_table_p->event_stats == NULL) {
554554
ERRDBG("Failed to allocate memory for cuptiu_table_p->event_stats.\n");
555555
return PAPI_ENOMEM;
556556
}
557557

558-
cuptiu_table_p->avail_gpu_info = (gpu_record_t *) papi_calloc(numDevicesOnMachine, sizeof(gpu_record_t));
558+
cuptiu_table_p->avail_gpu_info = (gpu_record_t *) calloc(numDevicesOnMachine, sizeof(gpu_record_t));
559559
if (cuptiu_table_p->avail_gpu_info == NULL) {
560560
ERRDBG("Failed to allocate memory for cuptiu_table_p->avail_gpu_info.\n");
561561
return PAPI_ENOMEM;
@@ -732,19 +732,19 @@ int cuptip_ctx_create(cuptic_info_t thr_info, cuptip_control_t *pstate, uint32_t
732732
{
733733
COMPDBG("Entering.\n");
734734

735-
cuptip_control_t state = (cuptip_control_t) papi_calloc (1, sizeof(struct cuptip_control_s));
735+
cuptip_control_t state = (cuptip_control_t) calloc (1, sizeof(struct cuptip_control_s));
736736
if (state == NULL) {
737737
SUBDBG("Failed to allocate memory for state.\n");
738738
return PAPI_ENOMEM;
739739
}
740740

741-
state->gpu_ctl = (cuptip_gpu_state_t *) papi_calloc(numDevicesOnMachine, sizeof(cuptip_gpu_state_t));
741+
state->gpu_ctl = (cuptip_gpu_state_t *) calloc(numDevicesOnMachine, sizeof(cuptip_gpu_state_t));
742742
if (state->gpu_ctl == NULL) {
743743
SUBDBG("Failed to allocate memory for state->gpu_ctl.\n");
744744
return PAPI_ENOMEM;
745745
}
746746

747-
long long *counters = (long long *) papi_malloc(num_events * sizeof(*counters));
747+
long long *counters = (long long *) malloc(num_events * sizeof(*counters));
748748
if (counters == NULL) {
749749
SUBDBG("Failed to allocate memory for counters.\n");
750750
return PAPI_ENOMEM;
@@ -1034,7 +1034,7 @@ int cuptip_ctx_read(cuptip_control_t state, long long **counters)
10341034
}
10351035
}
10361036
}
1037-
papi_free(metricValues);
1037+
free(metricValues);
10381038
*counters = counter_vals;
10391039

10401040
papi_errno = begin_pass();
@@ -1165,15 +1165,15 @@ int cuptip_ctx_destroy(cuptip_control_t *pstate)
11651165
// Free the created rawMetricRequests from cuptip_ctx_start
11661166
int j;
11671167
for (j = 0; j < state->gpu_ctl[i].numberOfRawMetricRequests; j++) {
1168-
papi_free((void *) state->gpu_ctl[i].rawMetricRequests[j].pMetricName);
1168+
free((void *) state->gpu_ctl[i].rawMetricRequests[j].pMetricName);
11691169
}
1170-
papi_free(state->gpu_ctl[i].rawMetricRequests);
1170+
free(state->gpu_ctl[i].rawMetricRequests);
11711171
}
11721172

11731173
// Free the allocated memory from cuptip_ctx_create
1174-
papi_free(state->counters);
1175-
papi_free(state->gpu_ctl);
1176-
papi_free(state);
1174+
free(state->counters);
1175+
free(state->gpu_ctl);
1176+
free(state);
11771177
*pstate = NULL;
11781178

11791179
return PAPI_OK;
@@ -1522,13 +1522,13 @@ static void shutdown_event_table(void)
15221522
{
15231523
cuptiu_table_p->count = 0;
15241524

1525-
papi_free(cuptiu_table_p->avail_gpu_info);
1525+
free(cuptiu_table_p->avail_gpu_info);
15261526
cuptiu_table_p->avail_gpu_info = NULL;
15271527

1528-
papi_free(cuptiu_table_p->events);
1528+
free(cuptiu_table_p->events);
15291529
cuptiu_table_p->events = NULL;
15301530

1531-
papi_free(cuptiu_table_p);
1531+
free(cuptiu_table_p);
15321532
cuptiu_table_p = NULL;
15331533
}
15341534

@@ -1545,7 +1545,7 @@ static void shutdown_event_stats_table(void)
15451545

15461546
cuptiu_table_p->event_stats_count = 0;
15471547

1548-
papi_free(cuptiu_table_p->event_stats);
1548+
free(cuptiu_table_p->event_stats);
15491549
}
15501550

15511551
/** @class cuptip_evt_enum

src/components/cuda/cupti_utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
int cuptiu_event_table_create_init_capacity(int capacity, int sizeof_rec, cuptiu_event_table_t **pevt_table)
1818
{
19-
cuptiu_event_table_t *evt_table = (cuptiu_event_table_t *) papi_malloc(sizeof(cuptiu_event_table_t));
19+
cuptiu_event_table_t *evt_table = (cuptiu_event_table_t *) malloc(sizeof(cuptiu_event_table_t));
2020
if (evt_table == NULL) {
2121
goto fn_fail;
2222
}
@@ -48,7 +48,7 @@ void cuptiu_event_table_destroy(cuptiu_event_table_t **pevt_table)
4848
evt_table->htable = NULL;
4949
}
5050

51-
papi_free(evt_table);
51+
free(evt_table);
5252
*pevt_table = NULL;
5353
}
5454

@@ -133,4 +133,4 @@ void free_vector(StringVector *vec) {
133133
}
134134
free(vec->arrayMetricStatistics);
135135
vec->arrayMetricStatistics = NULL;
136-
}
136+
}

src/components/cuda/htable.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ htable_insert(void *handle, const char *key, void *in)
121121
return htable_errno;
122122
fn_fail:
123123
if (entry) {
124-
papi_free(entry);
124+
free(entry);
125125
}
126126
goto fn_exit;
127127
}
@@ -196,13 +196,13 @@ create_table(uint64_t size, struct hash_table **table)
196196
{
197197
int htable_errno = HTABLE_SUCCESS;
198198

199-
*table = papi_calloc(1, sizeof(**table));
199+
*table = calloc(1, sizeof(**table));
200200
if (table == NULL) {
201201
htable_errno = HTABLE_ENOMEM;
202202
goto fn_exit;
203203
}
204204

205-
(*table)->buckets = papi_calloc(size, sizeof(*(*table)->buckets));
205+
(*table)->buckets = calloc(size, sizeof(*(*table)->buckets));
206206
if ((*table)->buckets == NULL) {
207207
htable_errno = HTABLE_ENOMEM;
208208
goto fn_exit;
@@ -220,11 +220,11 @@ destroy_table(struct hash_table *table)
220220
int htable_errno = HTABLE_SUCCESS;
221221

222222
if (table && table->buckets) {
223-
papi_free(table->buckets);
223+
free(table->buckets);
224224
}
225225

226226
if (table) {
227-
papi_free(table);
227+
free(table);
228228
}
229229

230230
return htable_errno;
@@ -258,7 +258,7 @@ move_table(struct hash_table *new_table, struct hash_table *old_table)
258258
old_table->size = new_table->size;
259259
old_table->buckets = new_table->buckets;
260260
new_table->buckets = NULL;
261-
papi_free(old_buckets);
261+
free(old_buckets);
262262

263263
return htable_errno;
264264
}
@@ -322,7 +322,7 @@ create_table_entry(const char *key, void *val, struct hash_table_entry **entry)
322322
{
323323
int htable_errno = HTABLE_SUCCESS;
324324

325-
*entry = papi_calloc(1, sizeof(**entry));
325+
*entry = calloc(1, sizeof(**entry));
326326
if (*entry == NULL) {
327327
return HTABLE_ENOMEM;
328328
}
@@ -337,8 +337,8 @@ int
337337
destroy_table_entry(struct hash_table_entry *entry)
338338
{
339339
int htable_errno = HTABLE_SUCCESS;
340-
papi_free(entry->key);
341-
papi_free(entry);
340+
free(entry->key);
341+
free(entry);
342342
return htable_errno;
343343
}
344344

src/components/cuda/linux-cuda.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ int update_native_events(cuda_control_t *ctl, NativeInfo_t *ntv_info,
449449
struct event_map_item sorted_events[PAPI_CUDA_MAX_COUNTERS];
450450

451451
if (ntv_count != ctl->num_events) {
452-
ctl->events_id = papi_realloc(ctl->events_id,
452+
ctl->events_id = realloc(ctl->events_id,
453453
ntv_count * sizeof(*ctl->events_id));
454454
if (ctl->events_id == NULL) {
455455
papi_errno = PAPI_ENOMEM;
@@ -642,7 +642,7 @@ static int cuda_cleanup_eventset(hwd_control_state_t *ctl)
642642
}
643643

644644
/* free int array of event id's and reset number of events */
645-
papi_free(cuda_ctl->events_id);
645+
free(cuda_ctl->events_id);
646646
cuda_ctl->events_id = NULL;
647647
cuda_ctl->num_events = 0;
648648

src/components/cuda/papi_cupti_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ int cuptic_ctxarr_create(cuptic_info_t *pinfo)
761761
}
762762

763763
/* allocate memory */
764-
*pinfo = (cuptic_info_t) papi_calloc (total_gpus, sizeof(*pinfo));
764+
*pinfo = (cuptic_info_t) calloc (total_gpus, sizeof(*pinfo));
765765
if (*pinfo == NULL) {
766766
return PAPI_ENOMEM;
767767
}
@@ -837,7 +837,7 @@ int cuptic_ctxarr_get_ctx(cuptic_info_t info, int gpu_idx, CUcontext *ctx)
837837

838838
int cuptic_ctxarr_destroy(cuptic_info_t *pinfo)
839839
{
840-
papi_free(*pinfo);
840+
free(*pinfo);
841841
*pinfo = NULL;
842842
return PAPI_OK;
843843
}

src/components/infiniband/linux-infiniband.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,12 @@ add_ib_device(const char* name, int port)
303303
return (0);
304304
}
305305

306-
new_dev->dev_name = strdup(name);
306+
new_dev->dev_name = papi_strdup(name);
307307
new_dev->dev_port = port;
308308
if (new_dev->dev_name==0)
309309
{
310310
PAPIERROR("cannot allocate memory for device internal fields");
311+
papi_free(new_dev->dev_name);
311312
papi_free(new_dev);
312313
return (0);
313314
}
@@ -328,8 +329,8 @@ add_ib_counter(const char* name, const char* file_name, int extended, ib_device_
328329
return (0);
329330
}
330331

331-
new_cnt->ev_name = strdup(name);
332-
new_cnt->ev_file_name = strdup(file_name);
332+
new_cnt->ev_name = papi_strdup(name);
333+
new_cnt->ev_file_name = papi_strdup(file_name);
333334
new_cnt->extended = extended;
334335
new_cnt->ev_device = device;
335336
if (new_cnt->ev_name==0 || new_cnt->ev_file_name==0)
@@ -599,9 +600,9 @@ deallocate_infiniband_resources()
599600
{
600601
for (i=0 ; i<num_events ; ++i) {
601602
if (infiniband_native_events[i].name)
602-
free(infiniband_native_events[i].name);
603+
papi_free(infiniband_native_events[i].name);
603604
if (infiniband_native_events[i].file_name)
604-
free(infiniband_native_events[i].file_name);
605+
papi_free(infiniband_native_events[i].file_name);
605606
if (infiniband_native_events[i].description)
606607
papi_free(infiniband_native_events[i].description);
607608
}
@@ -612,7 +613,7 @@ deallocate_infiniband_resources()
612613
while (iter != 0)
613614
{
614615
if (iter->dev_name)
615-
free(iter->dev_name);
616+
papi_free(iter->dev_name);
616617

617618
ib_device_t *tmp = iter;
618619
iter = iter->next;

src/components/net/linux-net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ generateNetEventList( void )
173173
} else if (last) {
174174
last->next = temp;
175175
} else {
176-
free(temp);
176+
papi_free(temp);
177177
fclose(fin);
178178
PAPIERROR("This shouldn't be possible\n");
179179
snprintf(_net_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN-2,

src/components/rocm/htable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ create_table_entry(const char *key, void *val, struct hash_table_entry **entry)
325325
if (*entry == NULL) {
326326
return HTABLE_ENOMEM;
327327
}
328-
(*entry)->key = strdup(key);
328+
(*entry)->key = papi_strdup(key);
329329
(*entry)->val = val;
330330
(*entry)->next = NULL;
331331

src/components/rocm_smi/htable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ create_table_entry(const char *key, void *val, struct hash_table_entry **entry)
325325
if (*entry == NULL) {
326326
return HTABLE_ENOMEM;
327327
}
328-
(*entry)->key = strdup(key);
328+
(*entry)->key = papi_strdup(key);
329329
(*entry)->val = val;
330330
(*entry)->next = NULL;
331331

0 commit comments

Comments
 (0)