diff options
| author | 2018-10-03 12:08:27 -0700 | |
|---|---|---|
| committer | 2018-10-03 14:01:40 -0700 | |
| commit | 3ebb48d10d8d478a1dbb9f2991f555c540d4d49a (patch) | |
| tree | 55b0a8c47d607b79c3227db06b94e707cef6bb51 | |
| parent | cd1ce760e8109eb91ce9d3e91fdaabb866262045 (diff) | |
LayerStats: Fix a use-after-free
std::string::c_str returns memory that's freed when the string dies. So,
this method should be returning the string, rather than a pointer to
it's freshly-deleted contents.
Caught by our static analyzer.
Bug: None
Test: Builds
Change-Id: I3dce7b60c6cfb4e3bfbd6c0dd6fe30dfe7f4313c
| -rw-r--r-- | services/surfaceflinger/LayerStats.cpp | 6 | ||||
| -rw-r--r-- | services/surfaceflinger/LayerStats.h | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/services/surfaceflinger/LayerStats.cpp b/services/surfaceflinger/LayerStats.cpp index 04ab121560..2a679552eb 100644 --- a/services/surfaceflinger/LayerStats.cpp +++ b/services/surfaceflinger/LayerStats.cpp @@ -68,7 +68,7 @@ void LayerStats::traverseLayerTreeStatsLocked( base::StringAppendF(&key, ",%s", layerCompositionType(layer->hwcCompositionType)); base::StringAppendF(&key, ",%d", layer->isProtected); base::StringAppendF(&key, ",%s", layerTransform(layer->hwcTransform)); - base::StringAppendF(&key, ",%s", layerPixelFormat(layer->activeBuffer.format)); + base::StringAppendF(&key, ",%s", layerPixelFormat(layer->activeBuffer.format).c_str()); base::StringAppendF(&key, ",%s", layer->dataspace.c_str()); base::StringAppendF(&key, ",%s", destinationLocation(layer->hwcFrame.left, layerGlobal.resolution[0], @@ -162,8 +162,8 @@ const char* LayerStats::layerCompositionType(int32_t compositionType) { return getCompositionName(static_cast<hwc2_composition_t>(compositionType)); } -const char* LayerStats::layerPixelFormat(int32_t pixelFormat) { - return decodePixelFormat(pixelFormat).c_str(); +std::string LayerStats::layerPixelFormat(int32_t pixelFormat) { + return decodePixelFormat(pixelFormat); } std::string LayerStats::scaleRatioWH(const LayerProtoParser::Layer* layer) { diff --git a/services/surfaceflinger/LayerStats.h b/services/surfaceflinger/LayerStats.h index 7a190fdb41..bd17d82781 100644 --- a/services/surfaceflinger/LayerStats.h +++ b/services/surfaceflinger/LayerStats.h @@ -50,7 +50,7 @@ private: // Return the name of the composition type static const char* layerCompositionType(int32_t compositionType); // Return the name of the pixel format - static const char* layerPixelFormat(int32_t pixelFormat); + static std::string layerPixelFormat(int32_t pixelFormat); // Calculate scale ratios of layer's width/height with rotation information static std::string scaleRatioWH(const LayerProtoParser::Layer* layer); // Calculate scale ratio from source to destination and convert to string |