Segmentation Fault

Discussion in 'General Linux' started by Galvin Burgos, Jan 6, 2014.

  1. Galvin Burgos

    Galvin Burgos New Member

    Jul 13, 2013
    Likes Received:
    Hello everyone! I'm having a bit of an issue with an application that I wrote. The particular issue is a segmentation fault.

    My application first filters names out of a text file and puts them in a dynamically allocated buffer with each name being terminated with a NULL character. Then an array of character pointers is created with each element of the array pointing to one of the names in the buffer effectively creating and array of strings. Then the application performs a merge sort on the array of strings. The application uses an additional thread to sort the top half of the array of strings while the main thread sorts the bottom half. Now the issue is that the application works perfectly fine when the file is around 33MB, but if the file is about 34MB or 35MB it produces a segmentation fault when it attempts to sort the list.
    The segmentation fault occurs when the final Merge_t() operation attempts to populate array2

    I'm working on a laptop with 1GB of memory installed so i'm wondering if maybe my system ran out of memory because the merge sort takes a recursive approach but with virtual memory I can't see how that would be the problem.

    utillib.c.txt --> functions to filter names from names.txt file and create a list of names as an array of strings.
    utillib.h.txt --> function prototypes for utillib.c.txt
    MergeSortLib.c.txt --> functions that implement the merge sort algorithm
    MergeSortLib.h.txt --> function prototypes for MergeSortLib.h.txt

    I greatly appreciate any help given!!

    Attached Files:

Share This Page