Browse Source

Fix segfault and memleak when getting many compressed server descs.

svn:r4956
Nick Mathewson 20 years ago
parent
commit
bd911d8612
1 changed files with 3 additions and 2 deletions
  1. 3 2
      src/or/directory.c

+ 3 - 2
src/or/directory.c

@@ -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,