1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-18 10:04:20 +03:00

mm: fix leak in fail path

If the dm_realloc would fail, the already allocate _maps_buffer
memory would have been lost (overwritten with NULL).
Fix this by using temporary line buffer.

Also add a minor cleanup to set end of buffer to '\0',
only when we really know the file size fits the preallocated buffer.
This commit is contained in:
Zdenek Kabelac 2013-05-13 12:59:38 +02:00
parent e926f22457
commit 55fe07ad98
2 changed files with 12 additions and 8 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.99 - Version 2.02.99 -
=================================== ===================================
Fix memory resource leak in memlocking error path.
Fix premature DM version checking which caused useless mapper/control access. Fix premature DM version checking which caused useless mapper/control access.
Add "active" LV reporting field to show activation state. Add "active" LV reporting field to show activation state.
Add "monitor" segment reporting field to show dmevent monitoring status. Add "monitor" segment reporting field to show dmevent monitoring status.

View File

@ -270,24 +270,27 @@ static int _memlock_maps(struct cmd_context *cmd, lvmlock_t lock, size_t *mstats
if (!_maps_buffer || len >= _maps_len) { if (!_maps_buffer || len >= _maps_len) {
if (_maps_buffer) if (_maps_buffer)
_maps_len *= 2; _maps_len *= 2;
if (!(_maps_buffer = dm_realloc(_maps_buffer, _maps_len))) { if (!(line = dm_realloc(_maps_buffer, _maps_len))) {
log_error("Allocation of maps buffer failed"); log_error("Allocation of maps buffer failed.");
return 0; return 0;
} }
_maps_buffer = line;
} }
if (lseek(_maps_fd, 0, SEEK_SET)) if (lseek(_maps_fd, 0, SEEK_SET))
log_sys_error("lseek", _procselfmaps); log_sys_error("lseek", _procselfmaps);
for (len = 0 ; len < _maps_len; len += n) { for (len = 0 ; len < _maps_len; len += n) {
if (!(n = read(_maps_fd, _maps_buffer + len, _maps_len - len))) { if (!(n = read(_maps_fd, _maps_buffer + len, _maps_len - len)))
_maps_buffer[len] = '\0';
break; /* EOF */ break; /* EOF */
if (n == -1) {
log_sys_error("read", _procselfmaps);
return 0;
} }
if (n == -1)
return_0;
} }
if (len < _maps_len) /* fits in buffer */ if (len < _maps_len) { /* fits in buffer */
_maps_buffer[len] = '\0';
break; break;
} }
}
line = _maps_buffer; line = _maps_buffer;
cn = find_config_tree_node(cmd, activation_mlock_filter_CFG); cn = find_config_tree_node(cmd, activation_mlock_filter_CFG);