title: Seg fault in C code with libtrace
body: <p>I write this code using libtrace but I got segmentation fault. I put all of my code here for clarification. anyone can help me where is the problem!
  I also should mention that the code want to sample some special packets base of the square coefficient.</p>
  
  <pre><code>int main(int argc,char **argv)
  {
      while(trace_read_packet(trace,packet)&gt; 0 ){
              if (filter &amp;&amp; !trace_apply_filter(filter,packet))
                  continue;
              if (packet-&gt;type &lt; TRACE_RT_DATA_SIMPLE)
                  /* Ignore RT messages */
                  continue;
                  numpackets ++;
              if (flag == true)
              {
                  first =trace_get_seconds(packet);
                  flag = false;
              }
              sizes[i] = trace_get_capture_length(packet);
              i++;
              randnumber = (double)rand() / (double)RAND_MAX;
              if(randnumber &lt;= probability)
              {
                      //trace_dump_packet(packet);
              trace_write_packet(output, packet);
              sampledpackets++;
              }
              next = trace_get_seconds(packet);
              if (double_t(next - first)== blocktime)
              {
                  scv = var(sizes, i);
                  scv = a_scv * scv + scv_error;
                  m = a_m * m + m_error;
                  n = 1 - (n/2);
                  probability = (ltqnorm(n)*e*scv) / m;
                  i =0;
                  flag = true;
              }
  
          }
  
          printf("\n");
          printf("number of packets is : %llu\n",numpackets);
          printf("number of sampled packet: %llu\n",sampledpackets);
  
          if (trace_is_err(trace)) {
              trace_perror(trace, "trace_read_packet");
          }
          trace_destroy(trace);
          trace_destroy_output(output);
      }
      return 0;
  }
  </code></pre>
  
  <p>Also, this is my memory output:</p>
  
  <pre><code>7fff18b1b000-7fff18b3c000 rw-p 00000000 00:00 0 [stack]
  7fff18bfe000-7fff18c00000 r-xp 00000000 00:00 0 [vdso]
  ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
  </code></pre>