From d6a07eeabbadbf846da7d6841340fc589d9a57aa Mon Sep 17 00:00:00 2001 From: Ruud van der Pas Date: Wed, 16 Oct 2024 16:12:06 +0000 Subject: [PATCH] gprofng: fix a memory leak in the mxv-pthreads example Fix a bug where the main program does not free the rows of the matrix. The memory for thread_data_arguments is also not released. In function check_results, the memory for the marker vector is not released. The usage of the verbose veriable has been extended to print more messages. gprofng/ChangeLog 2024-10-16 Ruud van der Pas PR 32273 PR 32274 * mxv-pthreads/src/main.c: add calls to free() to release the memory allocated for array A and vector marker. Improve the usage of the verbose variable. * mxv-pthreads/src/manage_data.c: add a diagnostic printf statement. * mxv-pthreads/src/mydefs.h: adapt prototype to match the changes in main.c. --- gprofng/examples/mxv-pthreads/src/main.c | 20 ++++++++++++------- .../examples/mxv-pthreads/src/manage_data.c | 6 ++++-- gprofng/examples/mxv-pthreads/src/mydefs.h | 3 +-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/gprofng/examples/mxv-pthreads/src/main.c b/gprofng/examples/mxv-pthreads/src/main.c index 625c60484d1..8596763b918 100644 --- a/gprofng/examples/mxv-pthreads/src/main.c +++ b/gprofng/examples/mxv-pthreads/src/main.c @@ -28,9 +28,10 @@ #include "mydefs.h" +bool verbose; + int main (int argc, char **argv) { - bool verbose = false; thread_data *thread_data_arguments; pthread_t *pthread_ids; @@ -62,8 +63,7 @@ int main (int argc, char **argv) &number_of_rows, &number_of_columns, &repeat_count, - &number_of_threads, - &verbose); + &number_of_threads); if (verbose) printf ("Verbose mode enabled\n"); @@ -191,11 +191,16 @@ int main (int argc, char **argv) * Release the allocated memory and end execution. * ----------------------------------------------------------------------------- */ + for (int64_t i=0; i