mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-20 08:06:18 +00:00
* 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:
@@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <stdio.h>
|
||||||
#include <torrent/path.h>
|
#include <torrent/path.h>
|
||||||
#include <torrent/data/file.h>
|
#include <torrent/data/file.h>
|
||||||
#include <torrent/data/file_list.h>
|
#include <torrent/data/file_list.h>
|
||||||
@@ -164,8 +164,8 @@ WindowFileList::redraw() {
|
|||||||
int first = 16 + std::min<unsigned int>(itr.depth(), 8);
|
int first = 16 + std::min<unsigned int>(itr.depth(), 8);
|
||||||
int last = std::max<unsigned int>(m_canvas->width() + 1, 16 + 12);
|
int last = std::max<unsigned int>(m_canvas->width() + 1, 16 + 12);
|
||||||
|
|
||||||
std::snprintf(buffer + first, last - first, "| %s",
|
snprintf(buffer + first, last - first, "| %s",
|
||||||
itr.depth() < (*itr)->path()->size() ? (*itr)->path()->at(itr.depth()).c_str() : "UNKNOWN");
|
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);
|
m_canvas->print_attributes(0, pos, buffer, buffer + std::strlen(buffer), &attributes);
|
||||||
|
|
||||||
|
|||||||
+15
-10
@@ -56,6 +56,16 @@
|
|||||||
|
|
||||||
namespace rpc {
|
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
|
void
|
||||||
SCgiTask::open(SCgi* parent, int fd) {
|
SCgiTask::open(SCgi* parent, int fd) {
|
||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
@@ -150,13 +160,10 @@ SCgiTask::event_read() {
|
|||||||
m_body = m_buffer;
|
m_body = m_buffer;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
char* tmp = new char[(m_bufferSize = contentSize)];
|
realloc_buffer((m_bufferSize = contentSize) + 1, m_body, std::distance(m_body, m_position));
|
||||||
std::memcpy(tmp, m_body, std::distance(m_body, m_position));
|
|
||||||
delete [] m_buffer;
|
|
||||||
|
|
||||||
m_position = tmp + std::distance(m_body, m_position);
|
m_position = m_buffer + std::distance(m_body, m_position);
|
||||||
m_buffer = tmp;
|
m_body = m_buffer;
|
||||||
m_body = tmp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,10 +210,8 @@ SCgiTask::event_error() {
|
|||||||
bool
|
bool
|
||||||
SCgiTask::receive_write(const char* buffer, uint32_t length) {
|
SCgiTask::receive_write(const char* buffer, uint32_t length) {
|
||||||
// Need to cast due to a bug in MacOSX gcc-4.0.1.
|
// 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)) {
|
if (length + 256 > std::max(m_bufferSize, (unsigned int)default_buffer_size))
|
||||||
delete [] m_buffer;
|
realloc_buffer(length + 256, NULL, 0);
|
||||||
m_buffer = new char[length + 256];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Who ever bothers to check the return value?
|
// 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);
|
int headerSize = sprintf(m_buffer, "Status: 200 OK\r\nContent-Type: text/xml\r\nContent-Length: %i\r\n\r\n", length);
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ public:
|
|||||||
utils::SocketFd& get_fd() { return *reinterpret_cast<utils::SocketFd*>(&m_fileDesc); }
|
utils::SocketFd& get_fd() { return *reinterpret_cast<utils::SocketFd*>(&m_fileDesc); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline void realloc_buffer(uint32_t size, const char* buffer, uint32_t bufferSize);
|
||||||
|
|
||||||
SCgi* m_parent;
|
SCgi* m_parent;
|
||||||
|
|
||||||
char* m_buffer;
|
char* m_buffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user