c - Segmentation fault when free large array of pointers -


My code runs with errors on small files but I get segmfault on large input (millions of lines). Please see some of the code below:

  element * unionFind (zero * data) {element * retVal = NULL; Retal = (element *) maulok (form of element); Rate Val- & gt; Data = data; Rate Val- & gt; Rank = 0; Rate Val- & gt; Leader = retal; Return rate; }   

main:
...

  int main (int argc, char * argv []) {char str [2048]; Char * v_S = NULL; Straight set * s_v = NULL; Count of rows in the input   

*

  long * v_L = (long *) malloc (sizeof (long) * Ct_lines); Element ** v = malloc (size of element) * ct_lines); Whereas (fgets (str, sizeof (str), fp) = null) {v_S = strtok (str, ":"); V_L [i] = Atoll (VCI); V [i] = unionFind (and v_L [i]); S_v = add_vertex (v_L [i], v [i]); I ++; } Fclose (fpose); For (i = 0; i & lt; ct_lines; i ++) // From here to default {Free (V [i]); V [i] = null; } Free (V); V = NULL; Free (v_L); V_L = Faucet; After each mlok you should know what malloc NULL is returned (which means the memory can be).    

As your program fails for large files, there is no need to read the code in detail, due to its failure it is running out of free memory and the malloc tap is coming back And then you're trying to save the structure elements at the top function findUnion to tap the address.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -