diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-04-21 02:22:38 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-06-24 14:20:37 +0200 |
commit | 2dd2341e0e1aae172f669d1810004ae72e3105d8 (patch) | |
tree | 1bddf68ffcb9f8c731ae8ad78ce83340d12a3eba /unix/common/randr.cxx | |
parent | 7aace8ea6da9c58782e74b3bfc5f8928b06d6853 (diff) | |
download | tigervnc-2dd2341e0e1aae172f669d1810004ae72e3105d8.tar.gz tigervnc-2dd2341e0e1aae172f669d1810004ae72e3105d8.zip |
Simplify RandR output name handling
Store the name in a std::string to make things less complex as we don't
need to be as careful about making sure the data is free():d.
Diffstat (limited to 'unix/common/randr.cxx')
-rw-r--r-- | unix/common/randr.cxx | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/unix/common/randr.cxx b/unix/common/randr.cxx index 12c4841f..e4e2d7be 100644 --- a/unix/common/randr.cxx +++ b/unix/common/randr.cxx @@ -236,10 +236,14 @@ static unsigned int _setScreenLayout(bool dryrun, /* Next, reconfigure all known outputs */ for (int i = 0;i < vncRandRGetOutputCount();i++) { unsigned int output; + char *name_; + std::string name; rfb::ScreenSet::const_iterator iter; output = vncRandRGetOutputId(i); + name = name_ = vncRandRGetOutputName(i); + free(name_); /* Known? */ if (outputIdMap->count(output) == 0) @@ -259,31 +263,24 @@ static unsigned int _setScreenLayout(bool dryrun, /* Probably not needed, but let's be safe */ if (!vncRandRIsOutputUsable(i)) { - if (logErrors) { - char *name = vncRandRGetOutputName(i); - vlog.error("Required output '%s' cannot be used", name); - free(name); - } + if (logErrors) + vlog.error("Required output '%s' cannot be used", name.c_str()); return rfb::resultInvalid; } /* Possible mode? */ if (!vncRandRCheckOutputMode(i, iter->dimensions.width(), iter->dimensions.height())) { - if (logErrors) { - char *name = vncRandRGetOutputName(i); - vlog.error("Output '%s' does not support required mode %dx%d", name, + if (logErrors) + vlog.error("Output '%s' does not support required mode %dx%d", + name.c_str(), iter->dimensions.width(), iter->dimensions.height()); - free(name); - } return rfb::resultInvalid; } - char *name = vncRandRGetOutputName(i); - vlog.debug("Reconfiguring output '%s' to %dx%d+%d+%d", name, + vlog.debug("Reconfiguring output '%s' to %dx%d+%d+%d", name.c_str(), iter->dimensions.width(), iter->dimensions.height(), iter->dimensions.tl.x, iter->dimensions.tl.y); - free(name); if (dryrun) continue; @@ -295,13 +292,11 @@ static unsigned int _setScreenLayout(bool dryrun, iter->dimensions.width(), iter->dimensions.height()); if (!ret) { - if (logErrors) { - char *name = vncRandRGetOutputName(i); - vlog.error("Failed to reconfigure output '%s' to %dx%d+%d+%d", name, + if (logErrors) + vlog.error("Failed to reconfigure output '%s' to %dx%d+%d+%d", + name.c_str(), iter->dimensions.width(), iter->dimensions.height(), iter->dimensions.tl.x, iter->dimensions.tl.y); - free(name); - } return rfb::resultInvalid; } } @@ -311,6 +306,8 @@ static unsigned int _setScreenLayout(bool dryrun, for (iter = layout.begin();iter != layout.end();++iter) { OutputIdMap::const_iterator oi; unsigned int output; + char *name_; + std::string name; int i; /* Does this screen have an output already? */ @@ -332,6 +329,8 @@ static unsigned int _setScreenLayout(bool dryrun, return rfb::resultInvalid; } output = vncRandRGetOutputId(i); + name = name_ = vncRandRGetOutputName(i); + free(name_); /* * Make sure we already have an entry for this, or @@ -342,31 +341,24 @@ static unsigned int _setScreenLayout(bool dryrun, /* Probably not needed, but let's be safe */ if (!vncRandRIsOutputUsable(i)) { - if (logErrors) { - char *name = vncRandRGetOutputName(i); - vlog.error("Required new output '%s' cannot be used", name); - free(name); - } + if (logErrors) + vlog.error("Required new output '%s' cannot be used", name.c_str()); return rfb::resultInvalid; } /* Possible mode? */ if (!vncRandRCheckOutputMode(i, iter->dimensions.width(), iter->dimensions.height())) { - if (logErrors) { - char *name = vncRandRGetOutputName(i); - vlog.error("New output '%s' does not support required mode %dx%d", name, + if (logErrors) + vlog.error("New output '%s' does not support required mode %dx%d", + name.c_str(), iter->dimensions.width(), iter->dimensions.height()); - free(name); - } return rfb::resultInvalid; } - char *name = vncRandRGetOutputName(i); - vlog.debug("Reconfiguring new output '%s' to %dx%d+%d+%d", name, + vlog.debug("Reconfiguring new output '%s' to %dx%d+%d+%d", name.c_str(), iter->dimensions.width(), iter->dimensions.height(), iter->dimensions.tl.x, iter->dimensions.tl.y); - free(name); if (dryrun) continue; @@ -378,13 +370,11 @@ static unsigned int _setScreenLayout(bool dryrun, iter->dimensions.width(), iter->dimensions.height()); if (!ret) { - if (logErrors) { - char *name = vncRandRGetOutputName(i); - vlog.error("Failed to reconfigure new output '%s' to %dx%d+%d+%d", name, + if (logErrors) + vlog.error("Failed to reconfigure new output '%s' to %dx%d+%d+%d", + name.c_str(), iter->dimensions.width(), iter->dimensions.height(), iter->dimensions.tl.x, iter->dimensions.tl.y); - free(name); - } return rfb::resultInvalid; } } |