Archived
1
0

fix segfaults

This commit is contained in:
Jeff Becker 2017-10-09 12:51:49 -04:00
parent e67e7a20bd
commit 579bf619f4
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
4 changed files with 16 additions and 10 deletions

View File

@ -28,7 +28,8 @@ namespace nntpchan {
void LineReader::OnLine(const char *d, const size_t l) 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); HandleLine(line);
} }

View File

@ -31,7 +31,7 @@ namespace nntpchan
std::istringstream s; std::istringstream s;
s.str(line); s.str(line);
for (std::string part; std::getline(s, part, ' '); ) { 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()) if(command.size())
HandleCommand(command); HandleCommand(command);
@ -59,14 +59,20 @@ namespace nntpchan
{ {
std::size_t diff = end - data ; std::size_t diff = end - data ;
if(m_article) if(m_article)
{
m_article->write(data, diff+2); m_article->write(data, diff+2);
m_article->flush();
}
ArticleObtained(); ArticleObtained();
diff += 5; diff += 5;
Data(end+5, l-diff); Data(end+5, l-diff);
return; return;
} }
if(m_article) if(m_article)
{
m_article->write(data, l); m_article->write(data, l);
m_article->flush();
}
} }
else else
Data(data, l); Data(data, l);
@ -141,7 +147,6 @@ namespace nntpchan
{ {
if(m_article) if(m_article)
{ {
m_article->flush();
m_article->close(); m_article->close();
m_article = nullptr; m_article = nullptr;
QueueLine("239 "+m_articleName); QueueLine("239 "+m_articleName);

View File

@ -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) { uv_read_start((uv_stream_t*) &m_conn, [] (uv_handle_t * h, size_t s, uv_buf_t * b) {
IServerConn * self = (IServerConn*) h->data; IServerConn * self = (IServerConn*) h->data;
if(self == nullptr) return; if(self == nullptr) return;
b->base = self->m_readbuff; b->base = new char[s];
if (s > sizeof(self->m_readbuff))
b->len = sizeof(self->m_readbuff);
else
b->len = s;
}, [] (uv_stream_t * s, ssize_t nread, const uv_buf_t * b) { }, [] (uv_stream_t * s, ssize_t nread, const uv_buf_t * b) {
IServerConn * self = (IServerConn*) s->data; IServerConn * self = (IServerConn*) s->data;
if(self == nullptr) return; if(self == nullptr) {
delete [] b->base;
return;
}
if(nread > 0) { if(nread > 0) {
b->base[nread] = 0;
self->m_handler->OnData(b->base, nread); self->m_handler->OnData(b->base, nread);
self->SendNextReply(); self->SendNextReply();
if(self->m_handler->ShouldClose()) if(self->m_handler->ShouldClose())
@ -108,6 +108,7 @@ namespace nntpchan
// got eof or error // got eof or error
self->Close(); self->Close();
} }
delete [] b->base;
}); });
} }

View File

@ -56,7 +56,6 @@ namespace nntpchan
uv_loop_t * m_loop; uv_loop_t * m_loop;
Server * m_parent; Server * m_parent;
IConnHandler * m_handler; IConnHandler * m_handler;
char m_readbuff[65536];
}; };
class Server class Server