comparison src/memline.c @ 15267:762fccd84b7c v8.1.0642

patch 8.1.0642: swapinfo() leaks memory commit https://github.com/vim/vim/commit/e6fdf79980c0f2856700d4f46de700293f477429 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 26 22:57:42 2018 +0100 patch 8.1.0642: swapinfo() leaks memory Problem: swapinfo() leaks memory. Solution: Avoid allocating the strings twice.
author Bram Moolenaar <Bram@vim.org>
date Wed, 26 Dec 2018 23:00:06 +0100
parents 19e79a1ed6b6
children 27783a6f430b
comparison
equal deleted inserted replaced
15266:f4d28214c3d3 15267:762fccd84b7c
2053 if ((fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) >= 0) 2053 if ((fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) >= 0)
2054 { 2054 {
2055 if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0)) 2055 if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0))
2056 { 2056 {
2057 if (ml_check_b0_id(&b0) == FAIL) 2057 if (ml_check_b0_id(&b0) == FAIL)
2058 dict_add_string(d, "error", 2058 dict_add_string(d, "error", (char_u *)"Not a swap file");
2059 vim_strsave((char_u *)"Not a swap file"));
2060 else if (b0_magic_wrong(&b0)) 2059 else if (b0_magic_wrong(&b0))
2061 dict_add_string(d, "error", 2060 dict_add_string(d, "error", (char_u *)"Magic number mismatch");
2062 vim_strsave((char_u *)"Magic number mismatch"));
2063 else 2061 else
2064 { 2062 {
2065 /* we have swap information */ 2063 /* we have swap information */
2066 dict_add_string(d, "version", vim_strnsave(b0.b0_version, 10)); 2064 dict_add_string_len(d, "version", b0.b0_version, 10);
2067 dict_add_string(d, "user", 2065 dict_add_string_len(d, "user", b0.b0_uname, B0_UNAME_SIZE);
2068 vim_strnsave(b0.b0_uname, B0_UNAME_SIZE)); 2066 dict_add_string_len(d, "host", b0.b0_hname, B0_HNAME_SIZE);
2069 dict_add_string(d, "host", 2067 dict_add_string_len(d, "fname", b0.b0_fname, B0_FNAME_SIZE_ORG);
2070 vim_strnsave(b0.b0_hname, B0_HNAME_SIZE));
2071 dict_add_string(d, "fname",
2072 vim_strnsave(b0.b0_fname, B0_FNAME_SIZE_ORG));
2073 2068
2074 dict_add_number(d, "pid", char_to_long(b0.b0_pid)); 2069 dict_add_number(d, "pid", char_to_long(b0.b0_pid));
2075 dict_add_number(d, "mtime", char_to_long(b0.b0_mtime)); 2070 dict_add_number(d, "mtime", char_to_long(b0.b0_mtime));
2076 dict_add_number(d, "dirty", b0.b0_dirty ? 1 : 0); 2071 dict_add_number(d, "dirty", b0.b0_dirty ? 1 : 0);
2077 # ifdef CHECK_INODE 2072 # ifdef CHECK_INODE
2078 dict_add_number(d, "inode", char_to_long(b0.b0_ino)); 2073 dict_add_number(d, "inode", char_to_long(b0.b0_ino));
2079 # endif 2074 # endif
2080 } 2075 }
2081 } 2076 }
2082 else 2077 else
2083 dict_add_string(d, "error", 2078 dict_add_string(d, "error", (char_u *)"Cannot read file");
2084 vim_strsave((char_u *)"Cannot read file"));
2085 close(fd); 2079 close(fd);
2086 } 2080 }
2087 else 2081 else
2088 dict_add_string(d, "error", vim_strsave((char_u *)"Cannot open file")); 2082 dict_add_string(d, "error", (char_u *)"Cannot open file");
2089 } 2083 }
2090 #endif 2084 #endif
2091 2085
2092 /* 2086 /*
2093 * Give information about an existing swap file. 2087 * Give information about an existing swap file.