Skip to content

Commit

Permalink
Merge pull request #6597 from jrafanie/leak_no_io_objects
Browse files Browse the repository at this point in the history
Open and close file objects using read to avoid leaking
  • Loading branch information
mzazrivec authored Jan 10, 2020
2 parents 298b657 + 05e02aa commit 0cd64bf
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def set_pre_prov_vars

unless %w[image_miq_request_new miq_template_miq_request_new].include?(params[:pressed])
path_to_report = ManageIQ::UI::Classic::Engine.root.join("product", "views", provisioning_report).to_s
@view = MiqReport.new(YAML.load(File.open(path_to_report)))
@view = MiqReport.new(YAML.load(File.read(path_to_report)))
@view.db = get_template_kls.to_s
report_scopes = %i[eligible_for_provisioning non_deprecated]
options = options_for_provisioning(@view.db, report_scopes)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller/performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def date_time_running_msg(typ, timestamp)

# Load a chart miq_report object from YML
def perf_get_chart_rpt(chart_rpt)
MiqReport.new(YAML.load(File.open("#{CHARTS_REPORTS_FOLDER}/#{chart_rpt}.yaml")))
MiqReport.new(YAML.load(File.read("#{CHARTS_REPORTS_FOLDER}/#{chart_rpt}.yaml")))
end

# Load a chart layout from YML
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller/timelines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def timeline_data
private ############################

def tl_get_rpt(timeline)
MiqReport.new(YAML.load(File.open("#{ApplicationController::TIMELINES_FOLDER}/miq_reports/#{timeline}.yaml")))
MiqReport.new(YAML.load(File.read("#{ApplicationController::TIMELINES_FOLDER}/miq_reports/#{timeline}.yaml")))
end

def tl_build_init_options(refresh = nil)
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/menu/yaml_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def load_custom_items
private

def load_custom_item(file_name)
properties = YAML.load(File.open(file_name))
properties = YAML.load(File.read(file_name))
if properties['type'] == 'section'
@sections << create_custom_menu_section(properties)
else
Expand Down
2 changes: 1 addition & 1 deletion app/services/charts_layout_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def layout
private

def build_charts
YAML.load(File.open(find_chart_path))
YAML.load(File.read(find_chart_path))
end

def find_chart_path
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_perf_options.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:javascript
miqInitSelectPicker();
- if @perf_options[:index] && %w(host vm).include?(request.parameters["controller"])
- rt_chart = YAML.load(File.open("#{ApplicationController::Performance::CHARTS_LAYOUTS_FOLDER}/realtime_perf_charts/#{@perf_options[:model]}.yaml"))
- rt_chart = YAML.load(File.read("#{ApplicationController::Performance::CHARTS_LAYOUTS_FOLDER}/realtime_perf_charts/#{@perf_options[:model]}.yaml"))
- @rt_hide = rt_chart[@perf_options[:index].to_i][:type] == "None"
- if request.parameters["controller"] == "storage" && @perf_options[:cat]
= select("perf", "typ", [[_("Hourly"), "Hourly"], [_("Daily"), "Daily"]], {:selected => @perf_options[:typ]},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
it "use report_name when is passed" do
report_name = "ProvisionCloudTemplates.yaml"
path_to_report = ManageIQ::UI::Classic::Engine.root.join("product", "views", report_name).to_s
view = MiqReport.new(YAML.load(File.open(path_to_report)))
view = MiqReport.new(YAML.load(File.read(path_to_report)))
expect(controller).to_not receive(:get_db_view)
controller.params = {:active_tree => "instances_tree"}
controller.params = {:model_name => "ManageIQ::Providers::CloudManager::Template"}
Expand Down
2 changes: 1 addition & 1 deletion spec/other/travis_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe 'travis.yml' do
let(:travis) { YAML.safe_load(File.open(ManageIQ::UI::Classic::Engine.root.join('.travis.yml'))) }
let(:travis) { YAML.safe_load(File.read(ManageIQ::UI::Classic::Engine.root.join('.travis.yml'))) }
let(:versions) { travis['rvm'] }

it "matches versions and excludes for multiple ruby versions" do
Expand Down
4 changes: 2 additions & 2 deletions spec/product/reports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

shared_examples "all report type examples" do |report_yaml|
let(:yaml) { report_yaml }
let(:report_data) { YAML.load(File.open(yaml)) }
let(:report_data) { YAML.load(File.read(yaml)) }

it 'defines headers that match col_order' do
col_order = report_data['col_order'].length
Expand All @@ -30,7 +30,7 @@
context "regular reports" do
shared_examples "regular report examples" do |report_yaml|
let(:yaml) { report_yaml }
let(:report_data) { YAML.load(File.open(yaml)) }
let(:report_data) { YAML.load(File.read(yaml)) }

it 'can be built even though without data' do
# TODO: ApplicationController::Performance::CHARTS_REPORTS_FOLDER
Expand Down
6 changes: 3 additions & 3 deletions spec/services/charts_layout_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
let(:host_redhat) { FactoryBot.create(:host_redhat) }
let(:vm_openstack) { FactoryBot.create(:vm_openstack) }
let(:host_openstack_infra_chart) do
YAML.load(File.open(File.join(ApplicationController::Performance::CHARTS_LAYOUTS_FOLDER, 'daily_perf_charts', 'ManageIQ_Providers_Openstack_InfraManager_Host') + '.yaml'))
YAML.load(File.read(File.join(ApplicationController::Performance::CHARTS_LAYOUTS_FOLDER, 'daily_perf_charts', 'ManageIQ_Providers_Openstack_InfraManager_Host') + '.yaml'))
end
let(:host_chart) do
YAML.load(File.open(File.join(ApplicationController::Performance::CHARTS_LAYOUTS_FOLDER, 'daily_perf_charts', 'Host') + '.yaml'))
YAML.load(File.read(File.join(ApplicationController::Performance::CHARTS_LAYOUTS_FOLDER, 'daily_perf_charts', 'Host') + '.yaml'))
end
let(:layout_chart) do
YAML.load(File.open(File.join(ApplicationController::Performance::CHARTS_LAYOUTS_FOLDER, 'daily_util_charts') + '.yaml'))
YAML.load(File.read(File.join(ApplicationController::Performance::CHARTS_LAYOUTS_FOLDER, 'daily_util_charts') + '.yaml'))
end

describe "#layout" do
Expand Down

0 comments on commit 0cd64bf

Please sign in to comment.