Fix some malloc/delete mismatches
This commit is contained in:
5
luprex/.gitignore
vendored
5
luprex/.gitignore
vendored
@@ -19,3 +19,8 @@ luajit/src/lj_recdef.h
|
|||||||
luajit/src/host/buildvm_arch.h
|
luajit/src/host/buildvm_arch.h
|
||||||
luajit/src/jit/vmdef.lua
|
luajit/src/jit/vmdef.lua
|
||||||
luajit/src/libluajit.a
|
luajit/src/libluajit.a
|
||||||
|
eris-master/src/lua
|
||||||
|
eris-master/src/luac
|
||||||
|
eris-master/test/persist
|
||||||
|
eris-master/test/unpersist
|
||||||
|
|
||||||
|
|||||||
@@ -57,59 +57,59 @@ public:
|
|||||||
bool connected_[MAX_CHAN];
|
bool connected_[MAX_CHAN];
|
||||||
bool short_sleep_;
|
bool short_sleep_;
|
||||||
std::map<int, SOCKET> listen_sockets_;
|
std::map<int, SOCKET> listen_sockets_;
|
||||||
std::unique_ptr<char> chbuf;
|
std::unique_ptr<char[]> chbuf;
|
||||||
int64_t basetime_;
|
int64_t basetime_;
|
||||||
|
|
||||||
int64_t get_now() {
|
int64_t get_now() {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, nullptr);
|
gettimeofday(&tv, nullptr);
|
||||||
int64_t tv_sec = tv.tv_sec;
|
int64_t tv_sec = tv.tv_sec;
|
||||||
int64_t tv_usec = tv.tv_usec;
|
int64_t tv_usec = tv.tv_usec;
|
||||||
return tv_sec * 1000000 + tv_usec;
|
return tv_sec * 1000000 + tv_usec;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOCKET open_connection(const std::string &target, std::string &err) {
|
SOCKET open_connection(const std::string &target, std::string &err) {
|
||||||
struct addrinfo *addrs = nullptr;
|
struct addrinfo *addrs = nullptr;
|
||||||
struct addrinfo *goodaddr = nullptr;
|
struct addrinfo *goodaddr = nullptr;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
SOCKET sock = INVALID_SOCKET;
|
SOCKET sock = INVALID_SOCKET;
|
||||||
std::string host, port;
|
std::string host, port;
|
||||||
char errbuf[1024];
|
char errbuf[1024];
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_protocol = IPPROTO_TCP;
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
hints.ai_flags = AI_NUMERICSERV;
|
hints.ai_flags = AI_NUMERICSERV;
|
||||||
|
|
||||||
err = "";
|
err = "";
|
||||||
util::split_host_port(target, host, port);
|
util::split_host_port(target, host, port);
|
||||||
int status = getaddrinfo(host.c_str(), port.c_str(), &hints, &addrs);
|
int status = getaddrinfo(host.c_str(), port.c_str(), &hints, &addrs);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
err = gai_strerror(status);
|
err = gai_strerror(status);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (addrs == nullptr) {
|
if (addrs == nullptr) {
|
||||||
err = "no such host found";
|
err = "no such host found";
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
goodaddr = addrs;
|
goodaddr = addrs;
|
||||||
assert(goodaddr->ai_family == AF_INET);
|
assert(goodaddr->ai_family == AF_INET);
|
||||||
assert(goodaddr->ai_socktype == SOCK_STREAM);
|
assert(goodaddr->ai_socktype == SOCK_STREAM);
|
||||||
assert(goodaddr->ai_protocol == IPPROTO_TCP);
|
assert(goodaddr->ai_protocol == IPPROTO_TCP);
|
||||||
sock = socket(goodaddr->ai_family, goodaddr->ai_socktype, goodaddr->ai_protocol);
|
sock = socket(goodaddr->ai_family, goodaddr->ai_socktype, goodaddr->ai_protocol);
|
||||||
assert(sock > 0);
|
assert(sock > 0);
|
||||||
set_nonblocking(sock);
|
set_nonblocking(sock);
|
||||||
status = connect(sock, goodaddr->ai_addr, goodaddr->ai_addrlen);
|
status = connect(sock, goodaddr->ai_addr, goodaddr->ai_addrlen);
|
||||||
if ((status != 0) && (errno != EINPROGRESS)) {
|
if ((status != 0) && (errno != EINPROGRESS)) {
|
||||||
goto error_errno;
|
goto error_errno;
|
||||||
}
|
}
|
||||||
freeaddrinfo(addrs);
|
freeaddrinfo(addrs);
|
||||||
return sock;
|
return sock;
|
||||||
|
|
||||||
error_errno:
|
error_errno:
|
||||||
strerror_r(errno, errbuf, 1024);
|
strerror_r(errno, errbuf, 1024);
|
||||||
err = errbuf;
|
err = errbuf;
|
||||||
error:
|
error:
|
||||||
if (sock != INVALID_SOCKET) close(sock);
|
if (sock != INVALID_SOCKET) close(sock);
|
||||||
if (addrs != nullptr) freeaddrinfo(addrs);
|
if (addrs != nullptr) freeaddrinfo(addrs);
|
||||||
@@ -121,7 +121,7 @@ public:
|
|||||||
err = "";
|
err = "";
|
||||||
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
|
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
assert(sock > 0);
|
assert(sock > 0);
|
||||||
|
|
||||||
struct sockaddr_in server;
|
struct sockaddr_in server;
|
||||||
server.sin_family = AF_INET;
|
server.sin_family = AF_INET;
|
||||||
server.sin_addr.s_addr = INADDR_ANY;
|
server.sin_addr.s_addr = INADDR_ANY;
|
||||||
@@ -200,19 +200,19 @@ public:
|
|||||||
while (true) {
|
while (true) {
|
||||||
driven_->drv_peek_outgoing(0, &nbytes, &bytes);
|
driven_->drv_peek_outgoing(0, &nbytes, &bytes);
|
||||||
if (nbytes == 0) break;
|
if (nbytes == 0) break;
|
||||||
int nwrote = write(1, bytes, nbytes);
|
int nwrote = write(1, bytes, nbytes);
|
||||||
assert(nwrote > 0);
|
assert(nwrote > 0);
|
||||||
driven_->drv_sent_outgoing(0, nwrote);
|
driven_->drv_sent_outgoing(0, nwrote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_console_input() {
|
void handle_console_input() {
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
while (true) {
|
while (true) {
|
||||||
int nread = read(0, buffer, 32);
|
int nread = read(0, buffer, 32);
|
||||||
if (nread == 0) break;
|
if (nread == 0) break;
|
||||||
assert(nread > 0);
|
assert(nread > 0);
|
||||||
driven_->drv_recv_incoming(0, nread, buffer);
|
driven_->drv_recv_incoming(0, nread, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,9 +240,9 @@ public:
|
|||||||
short_sleep_ = true;
|
short_sleep_ = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
|
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (errno == ECONNABORTED) {
|
if (errno == ECONNABORTED) {
|
||||||
// The remote disconnected before we had a chance to accept.
|
// The remote disconnected before we had a chance to accept.
|
||||||
// Just pretend it never happened.
|
// Just pretend it never happened.
|
||||||
@@ -286,8 +286,8 @@ public:
|
|||||||
timeout.tv_sec = mstimeout / 1000;
|
timeout.tv_sec = mstimeout / 1000;
|
||||||
timeout.tv_usec = (mstimeout - (timeout.tv_sec*1000)) * 1000;
|
timeout.tv_usec = (mstimeout - (timeout.tv_sec*1000)) * 1000;
|
||||||
int status = select(nfds, &rfds, &wfds, &efds, &timeout);
|
int status = select(nfds, &rfds, &wfds, &efds, &timeout);
|
||||||
assert(status >= 0);
|
assert(status >= 0);
|
||||||
|
|
||||||
for (auto &p : listen_sockets_) {
|
for (auto &p : listen_sockets_) {
|
||||||
if (FD_ISSET(p.second, &rfds) || FD_ISSET(p.second, &efds)) {
|
if (FD_ISSET(p.second, &rfds) || FD_ISSET(p.second, &efds)) {
|
||||||
accept_connections(p.first, p.second);
|
accept_connections(p.first, p.second);
|
||||||
@@ -324,8 +324,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void drive(DrivenEngine *de, int argc, char *argv[]) {
|
void drive(DrivenEngine *de, int argc, char *argv[]) {
|
||||||
enableRawMode();
|
enableRawMode();
|
||||||
init(de);
|
init(de);
|
||||||
DrivenEngine::set(de);
|
DrivenEngine::set(de);
|
||||||
basetime_ = get_now();
|
basetime_ = get_now();
|
||||||
driven_->drv_set_lua_source(util::read_lua_source("lua"));
|
driven_->drv_set_lua_source(util::read_lua_source("lua"));
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ StreamBuffer::StreamBuffer(const char *s, int64_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StreamBuffer::~StreamBuffer() {
|
StreamBuffer::~StreamBuffer() {
|
||||||
if (owned_ && (buf_lo_ != 0)) delete buf_lo_;
|
if (owned_ && (buf_lo_ != 0)) free(buf_lo_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t StreamBuffer::total_reads() const {
|
int64_t StreamBuffer::total_reads() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user