#vulnerable code 
                             protected boolean save(int index) {
		boolean result;
		int retVal;
		Result res;
		File file;
		BufferedWriter writer;
		
		retVal = m_FileChooser.showSaveDialog(this);
		if (retVal != JFileChooser.APPROVE_OPTION)
			return false;
		
		file = m_FileChooser.getSelectedFile();
		res  = getResultAt(index);
		try {
			writer = new BufferedWriter(new FileWriter(file));
			writer.append(res.toString());
			writer.flush();
			writer.close();
			result = true;
		}
		catch (Exception e) {
			result = false;
			System.err.println("Failed to write result to file '" + file + "':");
			e.printStackTrace();
			JOptionPane.showMessageDialog(
					this, 
					"Failed to write result to file '" + file + "':\n" + e, 
					"Error saving",
					JOptionPane.ERROR_MESSAGE);
		}
		
		return result;
	} 
                            #location 21 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                             protected boolean save(int index) {
		boolean result;
		int retVal;
		Result res;
		File file;
		
		retVal = m_FileChooser.showSaveDialog(this);
		if (retVal != JFileChooser.APPROVE_OPTION)
			return false;
		
		file = m_FileChooser.getSelectedFile();
		res  = getResultAt(index);
		try {
			Result.writeResultToFile(res, file.getAbsolutePath());
			result = true;
		}
		catch (Exception e) {
			result = false;
			System.err.println("Failed to write result to file '" + file + "':");
			e.printStackTrace();
			JOptionPane.showMessageDialog(
					this, 
					"Failed to write result to file '" + file + "':\n" + e, 
					"Error saving",
					JOptionPane.ERROR_MESSAGE);
		}
		
		return result;
	}