Hallo! Ich versuche ein mehrdimensionales Array zu reservieren mit einem Array auf Arrays. Ist das so ok? In meinem großen Programm kommt es zu komischen Fehlern, aber das Testprogramm scheint zu laufen?!

Code:
/* arraytest.c */

#include <stdio.h>
#include <stdlib.h>

#define FALSE 0
#define TRUE 1

typedef unsigned char   U1;
typedef signed int      S4;     /* LONGINT */

void **alloc_array_lint (S4 x, S4 y)
{
    void **array = NULL;
    S4 i, alloc;
    U1 err = FALSE;

    array = (void **) malloc (x * sizeof (S4 *));
    if (array != NULL)
    {
        for (i = 0; i < x; i++)
        {
            array[i] = (void *) malloc (y * sizeof (S4));
            if (array[i] == NULL)
            {
                alloc = i - 1;
                err = TRUE;
                break;
            }
        }
        if (err)
        {
            if (alloc >= 0)
            {
                for (i = 0; i <= alloc; i++)
                {
                    free (array[i]);
                }
            }
            free (array);
            array = NULL;
        }
    }

    return (array);
}

void dealloc_array_lint (S4 **array, S4 x)
{
    S4 i;

    for (i = 0; i < x; i++)
    {
        free (array[i]);
    }
    free (array);
}

int main ()
{
    S4 **array = NULL;

    array = (S4 **) alloc_array_lint (10, 10);
    if (array == NULL)
    {
        printf ("error can't allocate RAM for array!\n");
    }

    /* write */

    array[0][0] = 10;
    array[0][1] = 5;

    /* ... */

    dealloc_array_lint (array, 10);
}
Valgrind zeigte hier keine Fehler an. Ist das so ok?