Needing help with High Scores exercise

#include "high_scores.h"

int32_t latest(const int32_t *scores, size_t scores_len){
    return *(scores + scores_len - 1);
}

int32_t personal_best(const int32_t *scores, size_t scores_len){
    int32_t big = -1, cur = 0;
    for(size_t i = 0; i < scores_len; i++){
        cur = *(scores + i);
        if(cur > big) big = cur;
    }
    
    return big;
}

void insertSwap(int32_t** out, size_t* len, int32_t element){
    size_t i;
    for(i = 0; i < (*len); i++){
        if(element >= (*out)[i]) break;
    }

    if(element < (*out)[i - 1] && (*len) < 3){ /* SMALLEST */
        (*len)++; (*out) = (int32_t*) realloc((*out), (*len) * sizeof(int32_t)); 
        (*out)[i + 1] = element;
        return;
    }

    if((*len) < 3){
        (*len)++; (*out) = (int32_t*) realloc((*out), (*len) * sizeof(int32_t)); 
    }

    for(size_t j = (*len) - 1; j > i; j--){
        (*out)[j] = (*out)[j - 1];
    }

    (*out)[i] = element;
}

size_t personal_top_three(const int32_t *scores, size_t scores_len, int32_t *output){
    output = (int32_t*) malloc(sizeof(int32_t)); 
    
    output[0] = (*scores); size_t outlen = 1; int32_t cur;
    for(size_t i = 1; i < scores_len; i++){
        cur = *(scores + i);
        insertSwap(&output, &outlen, cur);
    }

    return outlen;
}

I am struggling to get if my method is way too convoluted or if my memory management is wrong.

Is a test failing? Which one? What is the message you’re getting?

In the solution above personal_top_three() allocates memory dynamically and overwrites the parameter output. Similarly, insertSwap() calls realloc() to get a larger array.
But that’s NOT how the parameter output is supposed to be used.

output is a pointer where personal_top_three should write the write its result. In layman’s terms: The caller gives the function space where it should write the (up to) three top scores. personal_top_three() does not have to (and should not) allocate memory for the three top scores.

Take a look at the tests. This is how personal_top_three() gets called:

static void check_personal_top_three(const int32_t *expected,
                                     size_t expected_len, const int32_t *scores,
                                     size_t scores_len)
{
   int32_t top_scores[TOP_SCORES_ARRAY_SIZE] = { 0 };

   size_t actual_len = personal_top_three(scores, scores_len, top_scores);

   TEST_ASSERT_EQUAL_INT32(expected_len, actual_len);

   if (expected_len > 0) {
      TEST_ASSERT_EQUAL_INT32_ARRAY(expected, top_scores, expected_len);
   }
}

This function creates an array top_scores of length TOP_SCORES_ARRAY_SIZE (3) and passes this array as the third argument to personal_top_three().
personal_top_three() is supposed to write to that array.