title: Memory access violation error c++
body: <p>I'm trying to exchange messages using multiple covert channels.
  So, basically, first i need to select the channel that i want to use for communication and then select the "destination_ip" of the user that i want to chat with and after that the </p>
  
  <blockquote>
    <p>processMessage()</p>
  </blockquote>
  
  <p>is called. Now, to move from one channel to another I have to close the existing connection and then open a new connection with the new channel that i want to use. My code below is modified to keep using the same channel after closing the connection and contain only the things that you need.</p>
  
  <pre><code>#include &lt;channelmanager.hpp&gt;
  #include &lt;thread&gt;
  #include &lt;iostream&gt;
  #include &lt;boost/test/unit_test.hpp&gt;
  #include &lt;boost/algorithm/string.hpp&gt;
  #include &lt;boost/lexical_cast.hpp&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;fstream&gt;
  #include &lt;openssl/hmac.h&gt;
  
  struct CommunicationFixture {
      CommunicationFixture() {
          channelmanager.setErrorStream(&amp;cout);
          channelmanager.setOutputStream(&amp;cout);
          destination_ip = "";
          channel_id = channelmanager.getChannelIDs()[0];
  
      }
      library::ChannelManager channelmanager;
      vector&lt;string&gt; last_adapters;
      string destination_ip;
      string channel_id = "";
  
  
      int processMessage(string message) {
          if (message.compare("exit") == 0) {
              channelmanager.closeConnection(destination_ip);
              return 1;
          }
          vector&lt;string&gt; arguments;
          boost::split(arguments, message, boost::is_any_of(" "), boost::token_compress_on);
          if (arguments[0].compare("argument") == 0) {
              if (arguments.size() &lt; 2) {
                  cout &lt;&lt; "Not enough arguments" &lt;&lt; endl;
                  return 0;
              }
              string argument_list = arguments[1];
              for (unsigned int i = 2; i &lt; arguments.size(); i++) {
                  argument_list += " " + arguments[i];
              }
              channelmanager.setChannelArguments(destination_ip, argument_list);
              cout &lt;&lt; "Set channel argument to '" &lt;&lt; argument_list &lt;&lt; "'." &lt;&lt; endl;
              return 0;
          }
          if (message.compare("help") == 0) {
              cout &lt;&lt; "Help not available in chat mode. Close chat first with 'exit'" &lt;&lt; endl;
              return 0;
          }
  
  
          channelmanager.openConnection(destination_ip, channel_id);
          channelmanager.sendMessage(destination_ip, message);
  
          return 0;
  
      }
  
      int close(string destination){
          cout &lt;&lt; "closing.." &lt;&lt; endl;
          channelmanager.closeConnection(destination); //I believe i have the error because of this!
          return 0;
      }
  
  };
  
  
  BOOST_FIXTURE_TEST_SUITE(communication, CommunicationFixture)
  
  BOOST_AUTO_TEST_CASE(basic_communication) {
  
      selectAdapterId(0);
      cout &lt;&lt; "Test" &lt;&lt; endl &lt;&lt; endl;
      printCommands();
      cout &lt;&lt; "Enter your command:" &lt;&lt; endl;
      string command;
      int code = 0;
      while (code != 2) {
          std::getline(cin, command);
          code = processCommand(command);
          if (code == 1) {
              // chat
              cout &lt;&lt; "chat started.." &lt;&lt; endl;
              int chatCode = 0;
  
  
              while (chatCode != 1) {
                  std::getline(cin, message);
                  close(destination_ip);
                  chatCode = processMessage(message);
                  channelmanager.setErrorStream(&amp;cout);
              }
              cout &lt;&lt; "chat ended." &lt;&lt; endl;
          }
      }
  
  
  
  }
  
  BOOST_AUTO_TEST_SUITE_END()
  </code></pre>
  
  <p>Note that, i think that the error happens due to the </p>
  
  <blockquote>
    <p>function close()</p>
  </blockquote>
  
  <p>because without it i don't get any errors. and the error doesn't happen immediately but after exchanging some messages. Here's the error:</p>
  
  <blockquote>
    <p>unknown location(0): fatal error: in
    "communication/basic_communication": memory access violation at
    address: 0x00000024: no mapping at fault address
    communicationTest.cpp(325): last checkpoint: "basic_communication"
    test entry</p>
  </blockquote>