diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2017-11-05 15:17:47 -0500 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2017-11-05 22:51:32 +0100 |
commit | 4058d85963e371be657f531d8f30e31381a9ccab (patch) | |
tree | a3589011ed3f0d755570802a93f5e0adb80e48c3 /vcl/unx | |
parent | 3b4fd34995262a161f30e1db8d087b0f01dfef37 (diff) |
PPDCache: fix segfault due to access after delete
Regression introduced in:
commit afe4d2527ec72e7493a2b1431559652ef45bebab
Author: Noel Grandin <noel.grandin@collabora.co.uk>
Date: Wed Oct 18 09:43:21 2017 +0200
use std::unique_ptr in PPDCache
Removing a naked pointer before inserting a possibly existing
one in a container is safe. This insured uniqueness (as the
comment suggests). However with unique_ptr, removal before
inserting deletes the pointer (when it exists), and the
insertion now taints the container with a wild pointer.
The fix is to skip adding if the pointer is already in the
container and add only when missing.
Change-Id: Ifc6b517451abb564949ccadfee10d98bf827540d
Reviewed-on: https://gerrit.libreoffice.org/44333
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/generic/printer/ppdparser.cxx | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx index d8bbd11e4b50..a2d8f45c8c42 100644 --- a/vcl/unx/generic/printer/ppdparser.cxx +++ b/vcl/unx/generic/printer/ppdparser.cxx @@ -576,15 +576,15 @@ const PPDParser* PPDParser::getParser( const OUString& rFile ) if( pNewParser ) { // this may actually be the SGENPRT parser, - // so ensure uniqueness here - rPPDCache.aAllParsers.erase( - std::remove_if( + // so ensure uniqueness here (but don't remove lest we delete us!) + if (std::find_if( rPPDCache.aAllParsers.begin(), rPPDCache.aAllParsers.end(), - [pNewParser] (std::unique_ptr<PPDParser> const & x) { return x.get() == pNewParser; } ), - rPPDCache.aAllParsers.end()); - // insert new parser to vector - rPPDCache.aAllParsers.emplace_back(pNewParser); + [pNewParser] (std::unique_ptr<PPDParser> const & x) { return x.get() == pNewParser; } ) == rPPDCache.aAllParsers.end()) + { + // insert new parser to vector + rPPDCache.aAllParsers.emplace_back(pNewParser); + } } return pNewParser; } |