From a94b333f09b7e3bc597edbc93a9d7a469fa3c680 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 20 Oct 2024 21:45:04 +0800 Subject: [PATCH] :bug: The corrupted data causes the kernel to hang https://github.com/siyuan-note/siyuan/issues/12852 --- kernel/model/file.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index 1e9904a67..ddeb9b7f9 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -118,14 +118,12 @@ func (box *Box) docIAL(p string) (ret map[string]string) { filePath := filepath.Join(util.DataDir, box.ID, p) filelock.Lock(filePath) - defer filelock.Unlock(filePath) - file, err := os.Open(filePath) if err != nil { logging.LogErrorf("open file [%s] failed: %s", p, err) + filelock.Unlock(filePath) return nil } - defer file.Close() iter := jsoniter.Parse(jsoniter.ConfigCompatibleWithStandardLibrary, file, 512) for field := iter.ReadObject(); field != ""; field = iter.ReadObject() { @@ -136,6 +134,8 @@ func (box *Box) docIAL(p string) (ret map[string]string) { iter.Skip() } } + file.Close() + filelock.Unlock(filePath) if 1 > len(ret) { logging.LogWarnf("properties not found in file [%s]", p)