title: Why does my program only work in the debugger?
body: <p>I'm using Dr. Memory for memory debugging of a C program I wrote today. This program, compiled with MinGW's gcc only works when I run it from the debugger gdb, so I'm assuming its a memory error. The results.txt file Dr. Memory returned to me is something like:</p>
  
  <pre><code>Dr. Memory version 1.5.0 build 5 builton Aug 31 2012 16:19:51
  Application cmdline: ""c:\Users\Lincoln\Desktop\USACO\gift1.exe""
  Recorded 63 suppression(s) from default c:\Program Files\Dr. Memory/bin/suppress-default.txt
  
  Error #1: UNINITIALIZED READ: reading register eflags
  # 0 replace_memcmp               [d:\derek\drmemory\withwiki\trunk\drmemory\replace.c:557]
  # 1 parseInputs                  [c:\Users\Lincoln\Desktop\USACO/gift1.c:55]
  # 2 main                         [c:\Users\Lincoln\Desktop\USACO/gift1.c:126]
  Note: @0:00:00.473 in thread 3824
  Note: instruction: jnz    $0x7388a607
  
  Error #2: UNINITIALIZED READ: reading register eax
  # 0 parseInputs               [c:\Users\Lincoln\Desktop\USACO/gift1.c:55]
  # 1 main                      [c:\Users\Lincoln\Desktop\USACO/gift1.c:126]
  Note: @0:00:00.473 in thread 3824
  Note: instruction: test   %eax %eax
  
  Error #3: UNINITIALIZED READ: reading register esi
  # 0 replace_memcmp               [d:\derek\drmemory\withwiki\trunk\drmemory\replace.c:556]
  # 1 parseInputs                  [c:\Users\Lincoln\Desktop\USACO/gift1.c:55]
  # 2 main                         [c:\Users\Lincoln\Desktop\USACO/gift1.c:126]
  Note: @0:00:00.474 in thread 3824
  Note: instruction: movzx  (%esi,%ecx,1) -&gt; %edi
  
  Error #4: UNADDRESSABLE ACCESS: reading 0x00000004-0x00000005 1 byte(s)
  # 0 replace_memcmp               [d:\derek\drmemory\withwiki\trunk\drmemory\replace.c:556]
  # 1 parseInputs                  [c:\Users\Lincoln\Desktop\USACO/gift1.c:55]
  # 2 main                         [c:\Users\Lincoln\Desktop\USACO/gift1.c:126]
  Note: @0:00:00.474 in thread 3824
  Note: instruction: movzx  (%esi,%ecx,1) -&gt; %edi
  </code></pre>
  
  <p>I have no idea how to read this, or where to start trying to fix my program. What do these error messages mean, and how do I fix them?</p>
  
  <p>EDIT: This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;math.h&gt;
  
  struct personsData {
      char * name;
      int accountMoney, receivedMoney, numAquaintances;
  };
  
  void parseInputs( FILE * fin, int NP, struct personsData * person ) {
  
      int i;
      for ( i = 0; i &lt; NP; i ++ )
          fscanf( fin, "%s", person[i].name );
  
      char * tempName_1;
      while ( !feof( fin ) ) {
  
          tempName_1 = malloc ( sizeof( char ) * 15 );
          fscanf( fin, "%s", tempName_1 );
  
          int index = 0;
          while ( memcmp( tempName_1, person[index].name, 15 ) != 0 )
              index ++;
          free( tempName_1 );
  
          fscanf( fin, "%d %d", &amp;person[index].accountMoney, &amp;person[index].numAquaintances );
  
          int b;
          char * tempName_2;
          for ( b = 0; b &lt; person[index].numAquaintances; b ++) {
              tempName_2 = malloc( sizeof( char ) * 15 );
              fscanf( fin, "%s", tempName_2 );
              i = 0;
              while ( memcmp( tempName_2, person[i].name, 15 ) != 0 )
                  i ++;
  
              free( tempName_2 );
  
              person[i].receivedMoney += ( int ) floor( person[index].accountMoney / person[index].numAquaintances );
              person[index].accountMoney = floor( person[index].accountMoney / person[index].numAquaintances ) * person[index].numAquaintances;
  
          }
      }
  
  }
  
  int main() {
  
      FILE * fin  = fopen ("gift1.in",  "r");
      FILE * fout = fopen ("gift1.out", "w");
  
      int NP;
      fscanf( fin, "%d", &amp;NP);
  
      struct personsData person[NP];
      int i;
      for ( i = 0; i &lt; NP; i ++ ) {
          person[i].accountMoney = 0;
          person[i].receivedMoney = 0;
          person[i].numAquaintances = 0;
          person[i].name = ( char * ) malloc ( sizeof( char ) * 15 );
      }
  
      parseInputs( fin, NP, person );
  
      for ( i = 0; i &lt; NP; i ++ ) {
          // print to output file (and also to console for development purposes
          fprintf( fout,  "%s %d\n", person[i].name, person[i].receivedMoney - person[i].accountMoney );
          printf(         "%s %d\n", person[i].name, person[i].receivedMoney - person[i].accountMoney );
      }
  
      for ( i = 0; i &lt; NP; i ++ ) {
          free( person[i].name );
      }
  
      exit(0);
  }
  </code></pre>
  
  <p>And this is the input file gift1.in:</p>
  
  <pre><code>5
  dave
  laura
  owen
  vick
  amr
  dave
  200 3
  laura
  owen
  vick
  owen
  500 1
  dave
  amr
  150 2
  vick
  owen
  laura
  0 2
  amr
  vick
  vick
  0 0
  </code></pre>