#vulnerable code 
                              public static Word2VecModel fromBinFile(File file, ByteOrder byteOrder)
      throws IOException {

    try (FileInputStream fis = new FileInputStream(file);) {
      DataInput in = (byteOrder == ByteOrder.BIG_ENDIAN) ?
          new DataInputStream(fis) : new SwappedDataInputStream(fis);

      StringBuilder sb = new StringBuilder();
      char c = (char) in.readByte();
      while (c != '\n') {
        sb.append(c);
        c = (char) in.readByte();
      }
      String firstLine = sb.toString();
      int index = firstLine.indexOf(' ');
      Preconditions.checkState(index != -1,
          "Expected a space in the first line of file '%s': '%s'",
          file.getAbsolutePath(), firstLine);

      int vocabSize = Integer.parseInt(firstLine.substring(0, index));
      int layerSize = Integer.parseInt(firstLine.substring(index + 1));

      List<String> vocabs = Lists.newArrayList();
      List<Double> vectors = Lists.newArrayList();

      for (int lineno = 0; lineno < vocabSize; lineno++) {
        sb = new StringBuilder();
        c = (char) in.readByte();
        while (c != ' ') {
          // ignore newlines in front of words (some binary files have newline,
          // some don't)
          if (c != '\n') {
            sb.append(c);
          }
          c = (char) in.readByte();
        }
        vocabs.add(sb.toString());

        for (int i = 0; i < layerSize; i++) {
          vectors.add((double) in.readFloat());
        }
      }

      return fromThrift(new Word2VecModelThrift()
          .setLayerSize(layerSize)
          .setVocab(vocabs)
          .setVectors(vectors));
    }
  } 
                            #location 44 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                              public static Word2VecModel fromBinFile(File file, ByteOrder byteOrder)
      throws IOException {

    try (FileInputStream fis = new FileInputStream(file);) {
			final FileChannel channel = fis.getChannel();
			final long oneGB = 1024 * 1024 * 1024;
			MappedByteBuffer buffer =
					channel.map(
							FileChannel.MapMode.READ_ONLY,
							0,
							Math.min(channel.size(), Integer.MAX_VALUE));
			buffer.order(byteOrder);
			int bufferCount = 1;
				// Java's NIO only allows memory-mapping up to 2GB. To work around this problem, we re-map
			  // every gigabyte. To calculate offsets correctly, we have to keep track how many gigabytes
			  // we've already skipped. That's what this is for.

      StringBuilder sb = new StringBuilder();
      char c = (char)buffer.get();
      while (c != '\n') {
        sb.append(c);
        c = (char)buffer.get();
      }
      String firstLine = sb.toString();
      int index = firstLine.indexOf(' ');
      Preconditions.checkState(index != -1,
					"Expected a space in the first line of file '%s': '%s'",
					file.getAbsolutePath(), firstLine);

			final int vocabSize = Integer.parseInt(firstLine.substring(0, index));
      final int layerSize = Integer.parseInt(firstLine.substring(index + 1));
			logger.info(
					String.format("Loading %d vectors with dimensionality %d", vocabSize, layerSize));

			List<String> vocabs = new ArrayList<String>(vocabSize);
			double vectors[] = new double[vocabSize * layerSize];

			long lastLogMessage = System.currentTimeMillis();
			final float[] floats = new float[layerSize];
      for (int lineno = 0; lineno < vocabSize; lineno++) {
				// read vocab
				sb.setLength(0);
        c = (char)buffer.get();
        while (c != ' ') {
          // ignore newlines in front of words (some binary files have newline,
          // some don't)
          if (c != '\n') {
            sb.append(c);
          }
          c = (char)buffer.get();
        }
        vocabs.add(sb.toString());

				// read vector
				final FloatBuffer floatBuffer = buffer.asFloatBuffer();
				floatBuffer.get(floats);
				for(int i = 0; i < floats.length; ++i) {
					vectors[lineno * layerSize + i] = floats[i];
				}
				buffer.position(buffer.position() + 4 * layerSize);

				// print log
				final long now = System.currentTimeMillis();
				if(now - lastLogMessage > 1000) {
					final double percentage = ((double)(lineno + 1) / (double)vocabSize) * 100.0;
					logger.info(
							String.format("Loaded %d/%d vectors (%f%%)", lineno + 1, vocabSize, percentage));
					lastLogMessage = now;
				}

				// remap file
				if(buffer.position() > oneGB) {
					final int newPosition = (int)(buffer.position() - oneGB);
					final long size = Math.min(channel.size() - oneGB * bufferCount, Integer.MAX_VALUE);
					logger.debug(
							String.format(
									"Remapping for GB number %d. Start: %d, size: %d",
									bufferCount,
									oneGB * bufferCount,
									size));
					buffer = channel.map(
							FileChannel.MapMode.READ_ONLY,
							oneGB * bufferCount,
							size);
					buffer.order(byteOrder);
					buffer.position(newPosition);
					bufferCount += 1;
				}
      }

			return new Word2VecModel(vocabs, layerSize,	vectors);
    }
  }