This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

problem with malloc?


I have written a C/C++ program that runs correctly using
MS Visual C++ 5.0, IBM Visual Age C++ 4.0, and gnu gcc 2.95 on Sparc
Solaris.  When I compile and try to run the same program on Linux the
program dumps core with a seg. fault. evidently generated in glibc
malloc.c.   Has anyone experienced a problem like this?

The line in the code that precipitates the seg. fault. is simply
allocating an pointer to make an array of pointers where the pointers
point to identical structures.  The structures are allocated using
Template code.  They are allocated using the "new" function.  I am trying
to come up with a simple
test program, but here is the gist of what I do.

i.e.

typedef struct ts {
    int ti;
    struct ts *next;
} TS ;

/* for each structure needed in in main program */
    new TS;

/* each TS created is linked into a linked list 
   then a list of pointers to each structure is created
   so that the list does not have to be iterated  each
    time a particular structure is needed */

    TS_pointers = ( TS ** )malloc( number_of_TSes*sizeof( TS * ) );

/* for each TS in list store a pointer to it in the array */
    TS_pointers[i] = temp_TS;
    temp_TS = a_TS->next;

Fred


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]