* Fixed a potential leak in scgi_task.cc.

* Removed std:: from snprintf in window_file_list.cc.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1052 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2008-04-15 11:50:14 +00:00
parent 41088740bd
commit 12b43d78a3
3 changed files with 20 additions and 13 deletions
+3 -3
View File
@@ -36,7 +36,7 @@
#include "config.h"
#include <cstdio>
#include <stdio.h>
#include <torrent/path.h>
#include <torrent/data/file.h>
#include <torrent/data/file_list.h>
@@ -164,8 +164,8 @@ WindowFileList::redraw() {
int first = 16 + std::min<unsigned int>(itr.depth(), 8);
int last = std::max<unsigned int>(m_canvas->width() + 1, 16 + 12);
std::snprintf(buffer + first, last - first, "| %s",
itr.depth() < (*itr)->path()->size() ? (*itr)->path()->at(itr.depth()).c_str() : "UNKNOWN");
snprintf(buffer + first, last - first, "| %s",
itr.depth() < (*itr)->path()->size() ? (*itr)->path()->at(itr.depth()).c_str() : "UNKNOWN");
m_canvas->print_attributes(0, pos, buffer, buffer + std::strlen(buffer), &attributes);
+15 -10
View File
@@ -56,6 +56,16 @@
namespace rpc {
// If bufferSize is zero then memcpy won't do anything.
inline void
SCgiTask::realloc_buffer(uint32_t size, const char* buffer, uint32_t bufferSize) {
char* tmp = new char[size];
std::memcpy(tmp, buffer, bufferSize);
delete [] m_buffer;
m_buffer = tmp;
}
void
SCgiTask::open(SCgi* parent, int fd) {
m_parent = parent;
@@ -150,13 +160,10 @@ SCgiTask::event_read() {
m_body = m_buffer;
} else {
char* tmp = new char[(m_bufferSize = contentSize)];
std::memcpy(tmp, m_body, std::distance(m_body, m_position));
delete [] m_buffer;
realloc_buffer((m_bufferSize = contentSize) + 1, m_body, std::distance(m_body, m_position));
m_position = tmp + std::distance(m_body, m_position);
m_buffer = tmp;
m_body = tmp;
m_position = m_buffer + std::distance(m_body, m_position);
m_body = m_buffer;
}
}
@@ -203,10 +210,8 @@ SCgiTask::event_error() {
bool
SCgiTask::receive_write(const char* buffer, uint32_t length) {
// Need to cast due to a bug in MacOSX gcc-4.0.1.
if (length + 256 > std::max(m_bufferSize, (unsigned int)default_buffer_size)) {
delete [] m_buffer;
m_buffer = new char[length + 256];
}
if (length + 256 > std::max(m_bufferSize, (unsigned int)default_buffer_size))
realloc_buffer(length + 256, NULL, 0);
// Who ever bothers to check the return value?
int headerSize = sprintf(m_buffer, "Status: 200 OK\r\nContent-Type: text/xml\r\nContent-Length: %i\r\n\r\n", length);
+2
View File
@@ -70,6 +70,8 @@ public:
utils::SocketFd& get_fd() { return *reinterpret_cast<utils::SocketFd*>(&m_fileDesc); }
private:
inline void realloc_buffer(uint32_t size, const char* buffer, uint32_t bufferSize);
SCgi* m_parent;
char* m_buffer;