[Spice-devel] [Win vdagent V2] vdagent: protect against NULL entry in _displays
Uri Lublin
uril at redhat.com
Thu May 9 07:17:52 PDT 2013
rhbz#958051
It may be that a _displays entry will be NULL.
I encountered it when running with multiple QXL devices, for one of
which the driver failed to load since it was "out of resources".
Iterations over _displays should handle that case.
We found four such iterations, and fixed them in this patch.
---
v1->v2: Added missing iteration found by Marc-Andre
In desktop_layout.cpp -- simplified the added code.
---
vdagent/desktop_layout.cpp | 7 +++++--
vdagent/vdagent.cpp | 9 ++++++---
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/vdagent/desktop_layout.cpp b/vdagent/desktop_layout.cpp
index c474edb..26b6b53 100644
--- a/vdagent/desktop_layout.cpp
+++ b/vdagent/desktop_layout.cpp
@@ -155,7 +155,7 @@ void DesktopLayout::normalize_displays_pos()
for (iter = _displays.begin(); iter != _displays.end(); iter++) {
mode = *iter;
- if (mode->_attached) {
+ if (mode && mode->_attached) {
min_x = min(min_x, mode->_pos_x);
min_y = min(min_y, mode->_pos_y);
max_x = max(max_x, mode->_pos_x + (LONG)mode->_width);
@@ -164,7 +164,10 @@ void DesktopLayout::normalize_displays_pos()
}
if (min_x || min_y) {
for (iter = _displays.begin(); iter != _displays.end(); iter++) {
- (*iter)->move_pos(-min_x, -min_y);
+ mode = *iter;
+ if (mode) {
+ mode->move_pos(-min_x, -min_y);
+ }
}
}
_total_width = max_x - min_x;
diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index 75291b0..a061973 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -618,7 +618,9 @@ bool VDAgent::handle_mon_config(VDAgentMonitorsConfig* mon_config, uint32_t port
display_count = _desktop_layout->get_display_count();
for (uint32_t i = 0; i < display_count; i++) {
DisplayMode* mode = _desktop_layout->get_display(i);
- ASSERT(mode);
+ if (!mode) {
+ continue;
+ }
if (i >= mon_config->num_of_monitors) {
vd_printf("%d. detached", i);
mode->set_attached(false);
@@ -748,8 +750,9 @@ void VDAgent::set_display_depth(uint32_t depth)
// setting depth for all the monitors, including unattached ones
for (uint32_t i = 0; i < display_count; i++) {
DisplayMode* mode = _desktop_layout->get_display(i);
- ASSERT(mode);
- mode->set_depth(depth);
+ if (mode) {
+ mode->set_depth(depth);
+ }
}
if (display_count) {
--
1.7.1
More information about the Spice-devel
mailing list