From 1a51bb53bfad42c0d18da95998b7324966c80e81 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 30 Oct 2018 01:28:34 -0400 Subject: [PATCH] context: cache result of home_fd() BeesContext::home_fd() is supposed to open $BEESHOME once and cache the Fd for later calls; however, instead it was reopening a new Fd each time it was called, and _also_ holding that Fd in a BeesContext member. Fds clean themselves up when they are forgotten, so it was not leaking per se, but it certainly had more open Fds than it needed to. Check to see if we have m_home_fd open, and return that if so. Signed-off-by: Zygo Blaxell --- src/bees-context.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bees-context.cc b/src/bees-context.cc index 7f99157..9d84b52 100644 --- a/src/bees-context.cc +++ b/src/bees-context.cc @@ -150,6 +150,10 @@ BeesContext::show_progress() Fd BeesContext::home_fd() { + if (!!m_home_fd) { + return m_home_fd; + } + const char *base_dir = getenv("BEESHOME"); if (!base_dir) { base_dir = ".beeshome";