#vulnerable code 
                             private static String hashPieces(File source)
		throws NoSuchAlgorithmException, IOException {
		long start = System.nanoTime();
		long hashTime = 0L;

		MessageDigest md = MessageDigest.getInstance("SHA-1");
		InputStream is = new BufferedInputStream(new FileInputStream(source));
		StringBuffer pieces = new StringBuffer();
		byte[] data = new byte[Torrent.PIECE_LENGTH];
		int read;

		while ((read = is.read(data)) > 0) {
			md.reset();
			md.update(data, 0, read);

			long hashStart = System.nanoTime();
			pieces.append(new String(md.digest(), Torrent.BYTE_ENCODING));
			hashTime += (System.nanoTime() - hashStart);
		}
		is.close();

		int n_pieces = new Double(Math.ceil((double)source.length() /
			Torrent.PIECE_LENGTH)).intValue();
		logger.info("Hashed {} ({} bytes) in {} pieces (total: {}ms, " +
			"{}ms hashing).",
			new Object[] {
				source.getName(),
				source.length(),
				n_pieces,
				String.format("%.1f", (System.nanoTime() - start) / 1024),
				String.format("%.1f", hashTime / 1024),
			});

		return pieces.toString();
	} 
                            #location 34 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                             private static String hashPieces(File source)
		throws NoSuchAlgorithmException, InterruptedException, IOException {

		ExecutorService executor = Executors.newFixedThreadPool(
			getHashingThreadsCount());
		List<Future<String>> results = new LinkedList<Future<String>>();
		byte[] data = new byte[Torrent.PIECE_LENGTH];
		int pieces = 0;
		int read;

		logger.info("Analyzing local data for {} with {} threads...",
			source.getName(), getHashingThreadsCount());
		long start = System.nanoTime();
		InputStream is = new BufferedInputStream(new FileInputStream(source));
		while ((read = is.read(data)) > 0) {
			results.add(executor.submit(new CallableChunkHasher(data, read)));
			pieces++;
		}
		is.close();

		// Request orderly executor shutdown and wait for hashing tasks to
		// complete.
		executor.shutdown();
		while (!executor.isTerminated()) {
			Thread.sleep(10);
		}
		long elapsed = System.nanoTime() - start;

		StringBuffer hashes = new StringBuffer();
		try {
			for (Future<String> chunk : results) {
				hashes.append(chunk.get());
			}
		} catch (ExecutionException ee) {
			throw new IOException("Error while hashing the torrent data!", ee);
		}

		int expectedPieces = new Double(Math.ceil((double)source.length() /
			Torrent.PIECE_LENGTH)).intValue();
		logger.info("Hashed {} ({} bytes) in {} pieces ({} expected) in {}ms.",
			new Object[] {
				source.getName(),
				source.length(),
				pieces,
				expectedPieces,
				String.format("%.1f", elapsed/1024.0/1024.0),
			});

		return hashes.toString();
	}