Fix segfault and memleak when getting many compressed server descs.

svn:r4956
This commit is contained in:
Nick Mathewson 2005-09-08 22:00:29 +00:00
parent 659491bbc6
commit bd911d8612

View File

@ -1222,16 +1222,17 @@ directory_handle_command_get(connection_t *conn, char *headers,
/* XXXX NM This could be way more efficiently handled. */ /* XXXX NM This could be way more efficiently handled. */
if (tor_gzip_compress(&compressed, &compressed_len, if (tor_gzip_compress(&compressed, &compressed_len,
inp, cp-inp, ZLIB_METHOD)<0) { inp, cp-inp, ZLIB_METHOD)<0) {
tor_free(cp); tor_free(inp);
smartlist_free(descs); smartlist_free(descs);
return -1; return -1;
} }
tor_free(cp); tor_free(inp);
tor_snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: application/octet-stream\r\n\r\n", tor_snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: application/octet-stream\r\n\r\n",
date, date,
(int)compressed_len); (int)compressed_len);
connection_write_to_buf(tmp, strlen(tmp), conn); connection_write_to_buf(tmp, strlen(tmp), conn);
connection_write_to_buf(compressed, compressed_len, conn); connection_write_to_buf(compressed, compressed_len, conn);
tor_free(compressed);
} else { } else {
tor_snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: application/octet-stream\r\n\r\n", tor_snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: application/octet-stream\r\n\r\n",
date, date,