fix memory leak

This commit is contained in:
Michael Zhang 2023-10-09 08:49:00 -05:00
parent a2f9e4a954
commit 607d210434
2 changed files with 14 additions and 2 deletions

View file

@ -136,6 +136,11 @@ int main(int argc, char **argv) {
printf("num correct: %d, out of %d (%.2f%%)\n", num_correct,
test_data->rows, (100.0 * num_correct) / test_data->rows);
free(test_data->buf);
free(test_label->buf);
free(test_data);
free(test_label);
}
free(w);

View file

@ -35,6 +35,8 @@ int main(int argc, char **argv) {
if (data->dimensions < thread_count)
thread_count = data->dimensions;
pthread_t *thread_pool = malloc(thread_count * sizeof(pthread_t));
int *wtf = malloc(thread_count * sizeof(int));
w = calloc(data->dimensions, sizeof(FLOAT));
new_w = calloc(data->dimensions, sizeof(FLOAT));
@ -49,8 +51,6 @@ int main(int argc, char **argv) {
double iter_start_time = monotonic_seconds();
// Spawn N threads
pthread_t *thread_pool = malloc(thread_count * sizeof(pthread_t));
int *wtf = malloc(thread_count * sizeof(int));
for (int t = 0; t < thread_count; ++t) {
wtf[t] = t;
pthread_create(&thread_pool[t], NULL, each_thread, &wtf[t]);
@ -99,6 +99,8 @@ int main(int argc, char **argv) {
free(labels->buf);
free(data);
free(labels);
free(thread_pool);
free(wtf);
// NOTE: NOT PART OF THE ASSIGNMENT
// Perform validation to see how well the model performs on training data
@ -123,6 +125,11 @@ int main(int argc, char **argv) {
printf("num correct: %d, out of %d (%.2f%%)\n", num_correct,
test_data->rows, (100.0 * num_correct) / test_data->rows);
free(test_data->buf);
free(test_label->buf);
free(test_data);
free(test_label);
}
free(w);