title: Segmentation fault (core dumped) over a 100 round loop bash script
body: <p>I know there are a lot of questions on that famous "Segmentation fault core dump", but for what I can see, C/C++ is involved in most of them. But my issue is specific to a bash script, so I am trying my luck here.</p>
  
  <p>I am running a simulator script (400+ lines so I cannot show you the code, can I ?) which sets and calculates a fight between two characters using dices and a profile (like you would do in a Dungeons and Dragons tabletop RPG). I have a reinitialisation function to reset the fight from scratch so that it can start a new one when there is a winner. At the end of the X rounds, some values from it are displayed (% hit, %block %hp per round, etc).</p>
  
  <p>If I set 1, 50 or 100 rounds (100 fights), it's okay, it runs perfectly. But over 130~ fights, all of sudden, it displays without any lag or other complications the "Segmentation fault (core dumped)" message. </p>
  
  <p>I have a general idea of what it is, but I cannot explain why it happens, I cannot resolve it, and I do not know what to do, or what to look for. </p>
  
  <p>Some notes I can say after browsing a lot of topics :</p>
  
  <p>There is no import, no based command system, no sed, awk, no array, no "complicated" command. I am just playing with variables (integer). No string. The most "complexe" command (to get a random number) is probably </p>
  
  <pre><code>(echo $((1 + RANDOM % 20))) 
  </code></pre>
  
  <p>All my conditions are like this </p>
  
  <pre><code>if [[ "$Skill_Block2" == "Yes" ]];
  then
  </code></pre>
  
  <p>With double bracket and variable between double quote (forgetting double quoted variable inside conditions could lead to problem, I heard).  </p>
  
  <p>There is no &amp;&amp; or || or -a or -o (I also read that using direct "if" statement would be better)</p>
  
  <p>The whole script is built around functions (easier to modify / implement). A function to calculate the damage is called by a function which check if a character can dodge the successful attack, which has been landed by another function allowing the success or the failure of that attack. Etc. I don't know if it is a good way of developping, but it "worked" so far. </p>
  
  <p>I have accents and French characters, but they seem to be well managed by my OS version (Ubuntu).</p>
  
  <p>I echo pretty much every single resolution so I can track mistakes. Perhaps displaying so much text is eating my virtual memory ? But I would never expect that on a Linux, to be honest. </p>
  
  <p>I don't think I have infinite loops since I can run it 50++ times without any problem in the exact same order.  </p>
  
  <p>To display the stats, I am using a dirty way (I think) : </p>
  
  <pre><code>touch statistique.txt
      echo "#|Player 1|Player 2" &gt; statistique.txt
      echo "ATT OK|$Number_Touch_OK1|$Number_Touch_OK1" &gt;&gt; statistique.txt
      echo "ATT Failed|$Number_Hit_Failed1|$Number_Hit_Failed2" &gt;&gt; statistique.txt
      echo "DEF Tried |$Number_Dodge_Tried1|$Number_Dodge_Tried2" &gt;&gt; statistique.txt
      [...]
      echo "Victory Number|$Victory1|$Victory2" &gt;&gt; statistique.txt
      echo " "
      column statistique.txt -t -s "|"
  </code></pre>
  
  <p>I tought about EOF, but I was not sure the variables would be interpreted. But at least I have a nicely formated text.</p>
  
  <p>My Ubuntu is run on my Windows. Might be the problem ?</p>
  
  <hr>
  
  <p>So here I am. I feel confused, and I am not very enthusiastic about posting this message as a wall of text without any code because it's too long (but if someone is brave enough, I can share the code, no problem). 
  I have seen too few message about memory leak on bash, so... I cannot imagine a Linux OS running out of memory  If you have any idea, advice, software (I tried Valgrind, but again, I am not sure it works with a bash script), please let me know. </p>
  
  <p>EDIT : here's the file (solveur.sh) :
  <a href="https://github.com/IlliciteS/script" rel="nofollow noreferrer">https://github.com/IlliciteS/script</a></p>