From b392c57c4af46ec32d4797983d353a84c6846e98 Mon Sep 17 00:00:00 2001 From: Mikkel Thestrup Date: Thu, 11 Dec 2025 23:59:40 +0100 Subject: Should just allocate this array on the stack --- src/cycle_detection.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/cycle_detection.c b/src/cycle_detection.c index 6f6c9af..4bbf62b 100644 --- a/src/cycle_detection.c +++ b/src/cycle_detection.c @@ -3,29 +3,21 @@ #include "linked_list.h" #include "vector.h" #include -#include #include void cycle_detection(Graph *g) { int n = g->num_vertices; - int *indegree = calloc(n, sizeof(int)); - if (!indegree) { - fprintf(stderr, "Memory allocation failed: could not create list.\n"); - free(indegree); - return; - } + int indegree[n]; LinkedList *queue = linked_list_new(); if (!queue) { fprintf(stderr, "Memory allocation failed: could not create queue.\n"); - free(indegree); return; } Vector *list = vector_new(); if (!list) { fprintf(stderr, "Memory allocation failed: could not create vector.\n"); - free(indegree); linked_list_delete(queue); return; } @@ -74,5 +66,4 @@ void cycle_detection(Graph *g) { linked_list_delete(queue); vector_delete(list); - free(indegree); } -- cgit v1.2.3-70-g09d2