title: invalid read size of 1 valgrind
body: <p>I've been scratching my hair out but can't seem to find what is wrong with the following code. Here is the small snippet of valgrind output that it generates</p>
  
  <blockquote>
    <p>Invalid read of size 1 at 0x4c22d82: strlen (mc_replace_strmem.c:242)
    by 0x5E65CA: Application::readConfigurationFile() (char_traits.h:262)
    by 0x5694BD: main Address 0xafc9660 is 24 bytes inside a block of size
    39 free'd at 0x4C20E0D: operator delete(void*)
    (vg_replace_malloc.c:342) by 0x635618:
    Configurator::getParameterValue(char const*, char**) by 0x5E65B2:
    Application:readConfigurationFile() (Application.cpp:77) by 0x5694BD:
    main</p>
  </blockquote>
  
  <pre><code>bool Configurator::getParameterValue(const char *p_pParameterName, char** p_pParameterValue)
  {
      bool blReturnValue = false;
  
      QDomElement element;
      QDomNode node;
      QDomNodeList list;
  
      list = doc.elementsByTagName(p_pParameterName);
      if (!list.isEmpty())  
      {
          node = list.item(0);
          element = node.toElement();
          QString qs = element.text().toUtf8();
          *p_pParameterValue = (char *)(qs.toStdString().c_str());
          blReturnValue = true;
      }
      else
      {
          char sMessage[200];
          sprintf(sMessage, "&lt;Configurator::getParameterValue&gt; Error! Parameter %s could not be found\n", p_pParameterName);
          m_outputFunction(sMessage);
      }
  
      return blReturnValue;
  }
  
  bool Configurator::parseFile()
  {
      bool blReturnValue = false;
  
      QString errorStr;
      int errorLine;
      int errorColumn;
  
      if (!doc.setContent((QIODevice*)(&amp;file), true, &amp;errorStr, &amp;errorLine, &amp;errorColumn))
      {
          char aTemp[512];
          sprintf(aTemp, "&lt;Configurator::parseFile&gt; error! can not read the file row: %d, column: %d:\n",errorLine, errorColumn);
          m_outputFunction(aTemp);
      }
      else
      {
          closeFile();
          blReturnValue = true;
      }
  
      return blReturnValue;
  }
  
  bool Application::readConfigurationFile()
  {
      bool blReturnValue = false;
  
      m_outputFunction("&lt;Application::readConfigurationFile&gt; Reading configuration..\n");
  
      if(m_configurator.parseFile())
      {
          blReturnValue = true;
  
          m_configurator.writeParameters();
  
          char *pTemp = 0;
  
  
          if(!m_configurator.getParameterValue("center_no", m_bCenterNo)) 
              m_bCenterNo = 1;
          if(m_configurator.getParameterValue("highway_header", &amp;pTemp))
              m_strHighwayHeader.assign(pTemp);
          else
              m_strHighwayHeader.assign("... HIGHWAY"); // Default value
      }
      return blReturnValue;
  }
  </code></pre>
  
  <p>Can somebody please tell me why I see invalid reads, I don't even use malloc/calloc in this code snippet.</p>