reports details on memory allocation error, and bypass broken rack middlewares

This commit is contained in:
roberto@mercury
2012-09-28 12:37:11 +02:00
parent 8e31bb612e
commit 973e508af7
2 changed files with 23 additions and 3 deletions
+2
View File
@@ -2154,6 +2154,8 @@ void *uwsgi_malloc(size_t size) {
char *ptr = malloc(size);
if (ptr == NULL) {
uwsgi_error("malloc()");
uwsgi_log("!!! tried memory allocation of %llu bytes !!!\n", (unsigned long long) size);
uwsgi_backtrace(uwsgi.backtrace_depth);
exit(1);
}
+21 -3
View File
@@ -128,7 +128,7 @@ VALUE rb_uwsgi_io_read(VALUE obj, VALUE args) {
struct wsgi_request *wsgi_req;
Data_Get_Struct(obj, struct wsgi_request, wsgi_req);
VALUE chunk;
unsigned int chunk_size;
long chunk_size;
/*
When EOF is reached, this method returns nil if length is given and not nil, or "" if length is not given or is nil.
@@ -153,7 +153,16 @@ VALUE rb_uwsgi_io_read(VALUE obj, VALUE args) {
}
// size specified
else if (RARRAY_LEN(args) > 0) {
chunk_size = NUM2UINT(RARRAY_PTR(args)[0]);
if (RARRAY_PTR(args)[0] == Qnil) {
chunk_size = wsgi_req->post_cl;
}
else {
chunk_size = NUM2LONG(RARRAY_PTR(args)[0]);
// hack to bypass broken middlewares
if (chunk_size <= 0) {
chunk_size = wsgi_req->post_cl;
}
}
char *tmp_chunk = uwsgi_malloc(chunk_size);
size_t rlen = fread(tmp_chunk, 1, chunk_size, (FILE *) wsgi_req->async_post);
// error, return Qnil
@@ -196,7 +205,16 @@ VALUE rb_uwsgi_io_read(VALUE obj, VALUE args) {
return chunk;
}
else if (RARRAY_LEN(args) > 0) {
chunk_size = NUM2UINT(RARRAY_PTR(args)[0]);
if (RARRAY_PTR(args)[0] == Qnil) {
chunk_size = wsgi_req->post_cl;
}
else {
chunk_size = NUM2LONG(RARRAY_PTR(args)[0]);
// hack to respect broken middlewares
if (chunk_size <= 0) {
chunk_size = wsgi_req->post_cl;
}
}
if (wsgi_req->buf_pos+chunk_size > wsgi_req->post_cl) {
chunk_size = wsgi_req->post_cl-wsgi_req->buf_pos;
}