Thread: SIGABRT on simple malloc

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    3

    SIGABRT on simple malloc

    Hi,
    I'm implementing the boyer moore algorithm and have had quite a lot of trouble with it so far. Firstly I had invalid reads, but those seem to be gone now. Now I'm getting a SIGABRT. which seems to be on the rule:
    'occ = (int*) malloc(256*sizeof(int));'
    part of the code:
    Code:
    int charsread, doubles, cursor, results, tlength,i;
    	char * t;
    	int *occ, *s;
    
    
    	FILE* file = fopen(fname, "rb");
            if (file == NULL) {
    			printf("%s\n", "Unable to open file");
    			return -1;
    		}
    	tlength = zlength * TSIZE;
    	results = 0;
    	cursor = 1;
    	charsread =0;
    		
            t = (char*) malloc(tlength * sizeof(char));
            if(t == NULL){
                    printf("%s\n", "Memory error");
                    return -1;
            }
    	
            
            s = (int*) malloc(zlength+1*sizeof(int));
            //alles 0 initialiseren
    	for(i =0;i<zlength+1; i++){
    		s[i] = 0;
    	}
            occ = (int*) malloc(256*sizeof(int));
            for(i = 0; i<256;i++){
    		occ[i] =-1;
    	}
    gdb gives:


    Breakpoint 1, processfile (fname=0x7fffffffe57c "search3/t.txt", z=0x603250 "needle", zlength=6) at search3/search3.c:117
    117 occ = (int*) malloc(256*sizeof(int));
    (gdb) s
    *__GI___libc_malloc (bytes=1024) at malloc.c:3615
    3615 malloc.c: No such file or directory.
    in malloc.c
    (gdb)
    When I let it run normally in gdb:

    Starting program: /home/kv/Dropbox/Ugent/Algoritmen en Datastructuren III/a.out search3/z.txt search3/t.txt
    a.out: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)
    ((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.

    Program received signal SIGABRT, Aborted.
    0x00007ffff7a8cba5 in *__GI_raise (sig=<value optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
    64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
    in ../nptl/sysdeps/unix/sysv/linux/raise.c

    Now, I really have no Idea what the problem could be now... Valgrind does not detect any problems it seems (?):
    ==5672== Memcheck, a memory error detector
    ==5672== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
    ==5672== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
    ==5672== Command: ./a.out search3/z.txt /search3/t.txt
    ==5672==
    --5672-- Valgrind options:
    --5672-- --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp
    --5672-- --leak-check=full
    --5672-- -v
    --5672-- --tool=memcheck
    --5672-- Contents of /proc/version:
    --5672-- Linux version 2.6.35-22-generic (buildd@yellow) (gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) ) #35-Ubuntu SMP Sat Oct 16 20:45:36 UTC 2010
    --5672-- Arch and hwcaps: AMD64, amd64-sse3-cx16
    --5672-- Page sizes: currently 4096, max supported 4096
    --5672-- Valgrind library directory: /usr/lib/valgrind
    --5672-- Reading syms from /home/kv/Dropbox/Ugent/Algoritmen en Datastructuren III/a.out (0x400000)
    --5672-- Reading syms from /lib/ld-2.12.1.so (0x4000000)
    --5672-- Considering /lib/ld-2.12.1.so ..
    --5672-- .. CRC mismatch (computed 7a804908 wanted b62d6d8e)
    --5672-- Considering /usr/lib/debug/lib/ld-2.12.1.so ..
    --5672-- .. CRC is valid
    --5672-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux (0x38000000)
    --5672-- object doesn't have a dynamic symbol table
    --5672-- Reading suppressions file: /usr/lib/valgrind/debian-libc6-dbg.supp
    --5672-- Reading suppressions file: /usr/lib/valgrind/default.supp
    --5672-- REDIR: 0x4018620 (strlen) redirected to 0x3803ee1f (vgPlain_amd64_linux_REDIR_FOR_strlen)
    --5672-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so (0x4a23000)
    --5672-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so (0x4c25000)
    ==5672== WARNING: new redirection conflicts with existing -- ignoring it
    --5672-- new: 0x04018620 (strlen ) R-> 0x04c292cf strlen
    --5672-- REDIR: 0x4018490 (index) redirected to 0x4c28f71 (index)
    --5672-- REDIR: 0x4018510 (strcmp) redirected to 0x4c2979b (strcmp)
    --5672-- Reading syms from /lib/libc-2.12.1.so (0x4e2e000)
    --5672-- Considering /lib/libc-2.12.1.so ..
    --5672-- .. CRC mismatch (computed cc0d5ab1 wanted 70d47059)
    --5672-- Considering /usr/lib/debug/lib/libc-2.12.1.so ..
    --5672-- .. CRC is valid
    --5672-- REDIR: 0x4eb2900 (__GI_strrchr) redirected to 0x4c28dde (__GI_strrchr)
    --5672-- REDIR: 0x4eaa320 (malloc) redirected to 0x4c280da (malloc)
    --5672-- REDIR: 0x4eb4a90 (memcpy) redirected to 0x4c2985d (memcpy)
    --5672-- REDIR: 0x4eabc10 (free) redirected to 0x4c27cea (free)
    --5672-- REDIR: 0x4eb0e40 (__GI_strlen) redirected to 0x4c2929b (__GI_strlen)
    Unable to open file
    --5672-- REDIR: 0x4eb6050 (strchrnul) redirected to 0x4c2a441 (strchrnul)
    --5672-- REDIR: 0x4eb41b0 (mempcpy) redirected to 0x4c2a4b2 (mempcpy)
    Total matches found: -1.
    ==5672==
    ==5672== HEAP SUMMARY:
    ==5672== in use at exit: 0 bytes in 0 blocks
    ==5672== total heap usage: 3 allocs, 3 frees, 1,142 bytes allocated
    ==5672==
    ==5672== All heap blocks were freed -- no leaks are possible
    ==5672==
    ==5672== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
    --5672--
    --5672-- used_suppression: 2 dl-hack3-cond-1
    --5672-- used_suppression: 2 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a
    ==5672==
    ==5672== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
    Google didn't give any interesting results so far... does anyone have an idea what this could be?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Try this an see what happens:
    Code:
    s = (int*) malloc((zlength+1)*sizeof(int));
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    EDIT: thanks dino. Stupid mistake.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    That's usually what it means. Are you freeing it as you go?
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    Yes.
    Everything is fine now. thanks a lot.
    Solved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with malloc() and sorting words from text file
    By goron350 in forum C Programming
    Replies: 11
    Last Post: 11-30-2004, 10:01 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. malloc always setting length of 8?
    By Zarkhalar in forum C++ Programming
    Replies: 7
    Last Post: 08-01-2004, 11:36 PM
  4. SIGABRT upon free()
    By registering in forum C Programming
    Replies: 2
    Last Post: 07-19-2003, 07:52 AM
  5. help with malloc
    By geetee in forum C Programming
    Replies: 1
    Last Post: 10-23-2001, 12:07 PM