Exemplo n.º 1
0
int main(int argc, char* argv[])
{
    if (argc != 2) {
        fprintf(stderr, "usage: %s file", argv[0]);
        exit(1);
    }

//    read_before(argv[1]);
    write_before(argv[1]);
}
Exemplo n.º 2
0
int main()
{
    char *some_memory[10]; /* an arrray of memory pointers */
    int exit_code = EXIT_FAILURE; /* set up exit code for failure */
    int i, j;

/* Call to mtrace routines in glibc library */
#ifdef MTRACE
    mtrace();  /* Turn on mtrace function */
#endif
    lmm_init();

    printf("Start of general malloc testing\n\n");

    printf("Start allocating 10 1k pieces of memory\n");
    for (i=0; i<10; i++)
    {
    some_memory[i] = (char *)malloc(ONE_K);
    printf ("Allocated a piece at 0x%x\n", (int)some_memory[i]);
    }
    printf("We have allocated some memory\n");
    printf("Now lets free part some memory\n");

    for (j=0; j<5; j++)
    {
    if (some_memory[j*2] != NULL) 
        {
        free(some_memory[j*2]);

        free(some_memory[j*2]);

        printf ("Freed a piece at 0x%x\n", (int)some_memory[j*2]);
        exit_code = EXIT_SUCCESS ;
        }
    }

    printf("\n\nNow let us check other functions\n\n");

#ifndef DMALLOC

    printf("Read after the end of the allocated string\n");

    post_read(); 

#endif

    printf("\nWrite after the end of the allocated string\n");

    post_write(); 

    printf ("\nRead before the allocated string\n");

    read_before(); 

#ifndef MTRACE

    printf("\nWrite before allocated area\n");

    write_before(); 

#endif

	lmm_dump_info();

    printf("\nMissed memory free of allocated string\n");

    miss_free();

#if !defined(MTRACE) && !defined(MEMWATCH) && !defined(DMALLOC)
    printf("\nUsing uninitialized memory\n");

    uninit_mem();

#endif

#ifdef MTRACE
    muntrace();  /* Turn off mtrace function */
#endif
	while(1);

    exit(exit_code);
}