diff options
author | electrodude <electrodude@users.noreply.github.com> | 2016-05-23 13:52:26 -0400 |
---|---|---|
committer | Auke Kok <sofar+github@foo-projects.org> | 2016-05-23 10:52:26 -0700 |
commit | 10bfa30b93a896c8c4a565ef3b9984c76ab4b592 (patch) | |
tree | 7fc1ca48c1966ef0d4ddb28f33f981b48d840b60 | |
parent | 649c7d79f6d70251d9da93ca1c648ca2d9cc5562 (diff) | |
download | pipeworks-10bfa30b93a896c8c4a565ef3b9984c76ab4b592.tar pipeworks-10bfa30b93a896c8c4a565ef3b9984c76ab4b592.tar.gz pipeworks-10bfa30b93a896c8c4a565ef3b9984c76ab4b592.tar.bz2 pipeworks-10bfa30b93a896c8c4a565ef3b9984c76ab4b592.tar.xz pipeworks-10bfa30b93a896c8c4a565ef3b9984c76ab4b592.zip |
Fixed settings file leak and invalid io.close (#136)
Before, init.lua called io.open on
pipeworks.worldpath..'/pipeworks_settings.txt'
to see if it existed, but did not close the resulting file handle if
it was found to exist. It instead erroneously called io.close() with
no argument, which does nothing if the default output file is set to
stdout, which it is.
Now, the result of io.open is saved to a local variable. If that value
is not nil (i.e. if the world settings file exists), the file handle is
passed to io.close before calling dofile.
Also, this saves pipeworks.worldpath..'/pipeworks_settings.txt' to a
local variable to reduce redundancy.
-rw-r--r-- | init.lua | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -16,9 +16,11 @@ pipeworks.modpath = minetest.get_modpath("pipeworks") dofile(pipeworks.modpath.."/default_settings.txt") -- Read the external config file if it exists. -if io.open(pipeworks.worldpath.."/pipeworks_settings.txt","r") then - dofile(pipeworks.worldpath.."/pipeworks_settings.txt") - io.close() +local worldsettingspath = pipeworks.worldpath.."/pipeworks_settings.txt","r" +local worldsettingsfile = io.open(worldsettingspath) +if worldsettingsfile then + worldsettingsfile:close() + dofile(worldsettingspath) end -- Random variables |