fix memory leak
This commit is contained in:
parent
a2f9e4a954
commit
607d210434
2 changed files with 14 additions and 2 deletions
|
@ -136,6 +136,11 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
printf("num correct: %d, out of %d (%.2f%%)\n", num_correct,
|
printf("num correct: %d, out of %d (%.2f%%)\n", num_correct,
|
||||||
test_data->rows, (100.0 * num_correct) / test_data->rows);
|
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);
|
free(w);
|
||||||
|
|
|
@ -35,6 +35,8 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
if (data->dimensions < thread_count)
|
if (data->dimensions < thread_count)
|
||||||
thread_count = data->dimensions;
|
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));
|
w = calloc(data->dimensions, sizeof(FLOAT));
|
||||||
new_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();
|
double iter_start_time = monotonic_seconds();
|
||||||
|
|
||||||
// Spawn N threads
|
// 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) {
|
for (int t = 0; t < thread_count; ++t) {
|
||||||
wtf[t] = t;
|
wtf[t] = t;
|
||||||
pthread_create(&thread_pool[t], NULL, each_thread, &wtf[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(labels->buf);
|
||||||
free(data);
|
free(data);
|
||||||
free(labels);
|
free(labels);
|
||||||
|
free(thread_pool);
|
||||||
|
free(wtf);
|
||||||
|
|
||||||
// NOTE: NOT PART OF THE ASSIGNMENT
|
// NOTE: NOT PART OF THE ASSIGNMENT
|
||||||
// Perform validation to see how well the model performs on training data
|
// 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,
|
printf("num correct: %d, out of %d (%.2f%%)\n", num_correct,
|
||||||
test_data->rows, (100.0 * num_correct) / test_data->rows);
|
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);
|
free(w);
|
||||||
|
|
Loading…
Reference in a new issue