fix segfaults
This commit is contained in:
		@@ -28,7 +28,8 @@ namespace nntpchan {
 | 
			
		||||
 | 
			
		||||
  void LineReader::OnLine(const char *d, const size_t l)
 | 
			
		||||
  {
 | 
			
		||||
    std::string line(d, l);
 | 
			
		||||
    std::string line;
 | 
			
		||||
    line += std::string(d, l);
 | 
			
		||||
    HandleLine(line);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,7 @@ namespace nntpchan
 | 
			
		||||
      std::istringstream s;
 | 
			
		||||
      s.str(line);
 | 
			
		||||
      for (std::string part; std::getline(s, part, ' '); ) {
 | 
			
		||||
          if(part.size()) command.push_back(std::string(part));
 | 
			
		||||
          if(part.size()) command.push_back(part);
 | 
			
		||||
      }
 | 
			
		||||
      if(command.size())
 | 
			
		||||
        HandleCommand(command);
 | 
			
		||||
@@ -59,14 +59,20 @@ namespace nntpchan
 | 
			
		||||
      {
 | 
			
		||||
        std::size_t diff = end - data ;
 | 
			
		||||
        if(m_article)
 | 
			
		||||
        {
 | 
			
		||||
          m_article->write(data, diff+2);
 | 
			
		||||
          m_article->flush();
 | 
			
		||||
        }
 | 
			
		||||
        ArticleObtained();
 | 
			
		||||
        diff += 5;
 | 
			
		||||
        Data(end+5, l-diff);
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      if(m_article)
 | 
			
		||||
      {
 | 
			
		||||
        m_article->write(data, l);
 | 
			
		||||
        m_article->flush();
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
      Data(data, l);
 | 
			
		||||
@@ -141,7 +147,6 @@ namespace nntpchan
 | 
			
		||||
  {
 | 
			
		||||
    if(m_article)
 | 
			
		||||
    {
 | 
			
		||||
      m_article->flush();
 | 
			
		||||
      m_article->close();
 | 
			
		||||
      m_article = nullptr;
 | 
			
		||||
      QueueLine("239 "+m_articleName);
 | 
			
		||||
 
 | 
			
		||||
@@ -86,15 +86,15 @@ namespace nntpchan
 | 
			
		||||
    uv_read_start((uv_stream_t*) &m_conn, [] (uv_handle_t * h, size_t s, uv_buf_t * b) {
 | 
			
		||||
        IServerConn * self = (IServerConn*) h->data;
 | 
			
		||||
        if(self == nullptr) return;
 | 
			
		||||
        b->base = self->m_readbuff;
 | 
			
		||||
        if (s > sizeof(self->m_readbuff))
 | 
			
		||||
          b->len = sizeof(self->m_readbuff);
 | 
			
		||||
        else
 | 
			
		||||
          b->len = s;
 | 
			
		||||
        b->base = new char[s];
 | 
			
		||||
      }, [] (uv_stream_t * s, ssize_t nread, const uv_buf_t * b) {
 | 
			
		||||
        IServerConn * self = (IServerConn*) s->data;
 | 
			
		||||
        if(self == nullptr) return;
 | 
			
		||||
        if(self == nullptr) {
 | 
			
		||||
          delete [] b->base;
 | 
			
		||||
          return;
 | 
			
		||||
        }
 | 
			
		||||
        if(nread > 0) {
 | 
			
		||||
          b->base[nread] = 0;
 | 
			
		||||
          self->m_handler->OnData(b->base, nread);
 | 
			
		||||
          self->SendNextReply();
 | 
			
		||||
          if(self->m_handler->ShouldClose())
 | 
			
		||||
@@ -108,6 +108,7 @@ namespace nntpchan
 | 
			
		||||
          // got eof or error
 | 
			
		||||
          self->Close();
 | 
			
		||||
        }
 | 
			
		||||
        delete [] b->base;
 | 
			
		||||
      });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -56,7 +56,6 @@ namespace nntpchan
 | 
			
		||||
    uv_loop_t * m_loop;
 | 
			
		||||
    Server * m_parent;
 | 
			
		||||
    IConnHandler * m_handler;
 | 
			
		||||
    char m_readbuff[65536];
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  class Server
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user