summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0642
blob: 40f7adc8f33248ec738a195bc73c7d34f20ca13b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0642
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0642
Problem:    swapinfo() leaks memory. (Christian Brabandt)
Solution:   Avoid allocating the strings twice.
Files:	    src/memline.c, src/dict.c, src/proto/dict.pro


*** ../vim-8.1.0641/src/memline.c	2018-12-25 23:15:41.795966567 +0100
--- src/memline.c	2018-12-26 22:51:14.081259880 +0100
***************
*** 2055,2075 ****
  	if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0))
  	{
  	    if (ml_check_b0_id(&b0) == FAIL)
! 		dict_add_string(d, "error",
! 			       vim_strsave((char_u *)"Not a swap file"));
  	    else if (b0_magic_wrong(&b0))
! 		dict_add_string(d, "error",
! 			       vim_strsave((char_u *)"Magic number mismatch"));
  	    else
  	    {
  		/* we have swap information */
! 		dict_add_string(d, "version", vim_strnsave(b0.b0_version, 10));
! 		dict_add_string(d, "user",
! 				     vim_strnsave(b0.b0_uname, B0_UNAME_SIZE));
! 		dict_add_string(d, "host",
! 				     vim_strnsave(b0.b0_hname, B0_HNAME_SIZE));
! 		dict_add_string(d, "fname",
! 				 vim_strnsave(b0.b0_fname, B0_FNAME_SIZE_ORG));
  
  		dict_add_number(d, "pid", char_to_long(b0.b0_pid));
  		dict_add_number(d, "mtime", char_to_long(b0.b0_mtime));
--- 2055,2070 ----
  	if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0))
  	{
  	    if (ml_check_b0_id(&b0) == FAIL)
! 		dict_add_string(d, "error", (char_u *)"Not a swap file");
  	    else if (b0_magic_wrong(&b0))
! 		dict_add_string(d, "error", (char_u *)"Magic number mismatch");
  	    else
  	    {
  		/* we have swap information */
! 		dict_add_string_len(d, "version", b0.b0_version, 10);
! 		dict_add_string_len(d, "user", b0.b0_uname, B0_UNAME_SIZE);
! 		dict_add_string_len(d, "host", b0.b0_hname, B0_HNAME_SIZE);
! 		dict_add_string_len(d, "fname", b0.b0_fname, B0_FNAME_SIZE_ORG);
  
  		dict_add_number(d, "pid", char_to_long(b0.b0_pid));
  		dict_add_number(d, "mtime", char_to_long(b0.b0_mtime));
***************
*** 2080,2091 ****
  	    }
  	}
  	else
! 	    dict_add_string(d, "error",
! 				    vim_strsave((char_u *)"Cannot read file"));
  	close(fd);
      }
      else
! 	dict_add_string(d, "error", vim_strsave((char_u *)"Cannot open file"));
  }
  #endif
  
--- 2075,2085 ----
  	    }
  	}
  	else
! 	    dict_add_string(d, "error", (char_u *)"Cannot read file");
  	close(fd);
      }
      else
! 	dict_add_string(d, "error", (char_u *)"Cannot open file");
  }
  #endif
  
*** ../vim-8.1.0641/src/dict.c	2018-12-21 16:04:16.312437516 +0100
--- src/dict.c	2018-12-26 22:46:22.175314033 +0100
***************
*** 370,382 ****
      int
  dict_add_string(dict_T *d, char *key, char_u *str)
  {
      dictitem_T	*item;
  
      item = dictitem_alloc((char_u *)key);
      if (item == NULL)
  	return FAIL;
      item->di_tv.v_type = VAR_STRING;
!     item->di_tv.vval.v_string = str != NULL ? vim_strsave(str) : NULL;
      if (dict_add(d, item) == FAIL)
      {
  	dictitem_free(item);
--- 370,402 ----
      int
  dict_add_string(dict_T *d, char *key, char_u *str)
  {
+     return dict_add_string_len(d, key, str, -1);
+ }
+ 
+ /*
+  * Add a string entry to dictionary "d".
+  * "str" will be copied to allocated memory.
+  * When "len" is -1 use the whole string, otherwise only this many bytes.
+  * Returns FAIL when out of memory and when key already exists.
+  */
+     int
+ dict_add_string_len(dict_T *d, char *key, char_u *str, int len)
+ {
      dictitem_T	*item;
+     char_u	*val = NULL;
  
      item = dictitem_alloc((char_u *)key);
      if (item == NULL)
  	return FAIL;
      item->di_tv.v_type = VAR_STRING;
!     if (str != NULL)
!     {
! 	if (len == -1)
! 	    val = vim_strsave(str);
! 	else
! 	    val = vim_strnsave(str, len);
!     }
!     item->di_tv.vval.v_string = val;
      if (dict_add(d, item) == FAIL)
      {
  	dictitem_free(item);
*** ../vim-8.1.0641/src/proto/dict.pro	2018-12-14 15:38:28.323597695 +0100
--- src/proto/dict.pro	2018-12-26 22:46:26.863281096 +0100
***************
*** 15,20 ****
--- 15,21 ----
  int dict_add(dict_T *d, dictitem_T *item);
  int dict_add_number(dict_T *d, char *key, varnumber_T nr);
  int dict_add_string(dict_T *d, char *key, char_u *str);
+ int dict_add_string_len(dict_T *d, char *key, char_u *str, int len);
  int dict_add_list(dict_T *d, char *key, list_T *list);
  int dict_add_dict(dict_T *d, char *key, dict_T *dict);
  long dict_len(dict_T *d);
*** ../vim-8.1.0641/src/version.c	2018-12-26 22:04:35.494546386 +0100
--- src/version.c	2018-12-26 22:56:06.859194439 +0100
***************
*** 801,802 ****
--- 801,804 ----
  {   /* Add new patch number below this line */
+ /**/
+     642,
  /**/

-- 
"I simultaneously try to keep my head in the clouds and my feet on the
ground.  Sometimes it's a stretch, though."              -- Larry Wall

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///