CLEANUP: cfgparse: de-uglify early file error handling in readcfgfile()
authorWilly Tarreau <w@1wt.eu>
Tue, 27 Apr 2021 16:30:28 +0000 (18:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 28 Apr 2021 09:21:32 +0000 (11:21 +0200)
commitda543e130cbaab91c96b1ecb96118141441bce4a
tree7dce67e70fd5e512fd40b5d55545865fe4abb980
parent59c5335dbe913230aaa8869eccd33cb7266afaee
CLEANUP: cfgparse: de-uglify early file error handling in readcfgfile()

In readcfgfile() when malloc() fails to allocate a buffer for the
config line, it currently says "parsing[<file>]: out of memory" while
the error is unrelated to the config file and may make one think it has
to do with the file's size. The second test (fopen() returning error)
needs to release the previously allocated line. Both directly return -1
which is not even documented as a valid error code for the function.

Let's simply make sure that the few variables freed at the end are
properly preset, and jump there upon error, after having displayed a
meaningful error message. Now at least we can get this:

  $ ./haproxy -f /dev/kmem
  [NOTICE] 116/191904 (23233) : haproxy version is 2.4-dev17-c3808c-13
  [NOTICE] 116/191904 (23233) : path to executable is ./haproxy
  [ALERT] 116/191904 (23233) : Could not open configuration file /dev/kmem : Permission denied
src/cfgparse.c