Bug Summary

File:home/maarten/src/libreoffice/core/sd/source/ui/unoidl/sddetect.cxx
Warning:line 131, column 12
Potential leak of memory pointed to by 'aStorage.pObj'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name sddetect.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/sd/inc -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sd/source/ui/unoidl/sddetect.cxx
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "sddetect.hxx"
21
22#include <com/sun/star/beans/PropertyValue.hpp>
23#include <cppuhelper/supportsservice.hxx>
24#include <com/sun/star/io/XInputStream.hpp>
25#include <com/sun/star/ucb/ContentCreationException.hpp>
26#include <com/sun/star/uno/XComponentContext.hpp>
27#include <vcl/graphicfilter.hxx>
28#include <sfx2/docfile.hxx>
29#include <sfx2/docfilt.hxx>
30#include <sfx2/fcontnr.hxx>
31#include <vcl/FilterConfigItem.hxx>
32#include <sot/storage.hxx>
33#include <unotools/mediadescriptor.hxx>
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::io;
38using namespace ::com::sun::star::task;
39using namespace ::com::sun::star::beans;
40using namespace ::com::sun::star::lang;
41using utl::MediaDescriptor;
42
43SdFilterDetect::SdFilterDetect()
44{
45}
46
47SdFilterDetect::~SdFilterDetect()
48{
49}
50
51OUString SAL_CALL SdFilterDetect::detect( Sequence< beans::PropertyValue >& lDescriptor )
52{
53 MediaDescriptor aMediaDesc( lDescriptor );
54 OUString aTypeName = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME(), OUString() );
55 uno::Reference< io::XInputStream > xInStream ( aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()], uno::UNO_QUERY );
56 if ( !xInStream.is() )
1
Taking false branch
57 return OUString();
58
59 SfxMedium aMedium;
60 aMedium.UseInteractionHandler( false );
61 aMedium.setStreamToLoadFrom( xInStream, true );
62
63 SvStream *pInStrm = aMedium.GetInStream();
64 if ( !pInStrm || pInStrm->GetError() )
2
Assuming 'pInStrm' is non-null
3
Taking false branch
65 return OUString();
66
67 if ( aTypeName.startsWith( "impress_MS_PowerPoint_97" ) )
4
Taking true branch
68 {
69 // Do not attempt to create an SotStorage on a
70 // 0-length stream as that would create the compound
71 // document header on the stream and effectively write to
72 // disk!
73 pInStrm->Seek( STREAM_SEEK_TO_BEGIN0L );
74 if ( pInStrm->remainingSize() == 0 )
5
Assuming the condition is false
6
Taking false branch
75 return OUString();
76
77 try
78 {
79 tools::SvRef<SotStorage> aStorage = new SotStorage( pInStrm, false );
7
Memory is allocated
80 if ( !aStorage->GetError() && aStorage->IsStream( "PowerPoint Document" ) )
8
Taking false branch
81 return aTypeName;
82 }
83 catch (const css::ucb::ContentCreationException&)
84 {
85 }
86 }
87 else
88 {
89 pInStrm->Seek( STREAM_SEEK_TO_BEGIN0L );
90
91 const OUString aFileName( aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), OUString() ) );
92 GraphicDescriptor aDesc( *pInStrm, &aFileName );
93 if( !aDesc.Detect() )
94 {
95 INetURLObject aCheckURL( aFileName );
96 if( aCheckURL.getExtension().equalsIgnoreAsciiCase("cgm") )
97 {
98 sal_uInt8 n8;
99 pInStrm->Seek( STREAM_SEEK_TO_BEGIN0L );
100 pInStrm->ReadUChar( n8 );
101 if ( ( n8 & 0xf0 ) == 0 )
102 // we are supporting binary cgm format only, so
103 // this is a small test to exclude cgm text
104 return "impress_CGM_Computer_Graphics_Metafile";
105 }
106 }
107 else
108 {
109 OUString aShortName( GraphicDescriptor::GetImportFormatShortName( aDesc.GetFileFormat() ) );
110 GraphicFilter &rGrfFilter = GraphicFilter::GetGraphicFilter();
111 const OUString aName( rGrfFilter.GetImportFormatTypeName( rGrfFilter.GetImportFormatNumberForShortName( aShortName ) ) );
112
113 if ( aShortName.equalsIgnoreAsciiCase( "PCD" ) ) // there is a multiple pcd selection possible
114 {
115 sal_Int32 nBase = 2; // default Base0
116 if ( aTypeName == "pcd_Photo_CD_Base4" )
117 nBase = 1;
118 else if ( aTypeName == "pcd_Photo_CD_Base16" )
119 nBase = 0;
120 FilterConfigItem aFilterConfigItem( "Office.Common/Filter/Graphic/Import/PCD" );
121 aFilterConfigItem.WriteInt32( "Resolution" , nBase );
122 }
123
124 SfxFilterMatcher aMatch("sdraw");
125 std::shared_ptr<const SfxFilter> pFilter = aMatch.GetFilter4FilterName( aName );
126 if ( pFilter )
127 return pFilter->GetRealTypeName();
128 }
129 }
130
131 return OUString();
9
Potential leak of memory pointed to by 'aStorage.pObj'
132}
133
134// XServiceInfo
135OUString SAL_CALL SdFilterDetect::getImplementationName()
136{
137 return "com.sun.star.comp.draw.FormatDetector";
138}
139
140// XServiceInfo
141sal_Bool SAL_CALL SdFilterDetect::supportsService( const OUString& sServiceName )
142{
143 return cppu::supportsService(this, sServiceName);
144}
145
146// XServiceInfo
147Sequence< OUString > SAL_CALL SdFilterDetect::getSupportedServiceNames()
148{
149 return { "com.sun.star.frame.ExtendedTypeDetection" };
150}
151
152
153extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface*
154com_sun_star_comp_draw_FormatDetector_get_implementation(css::uno::XComponentContext*,
155 css::uno::Sequence<css::uno::Any> const &)
156{
157 return cppu::acquire(new SdFilterDetect());
158}
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */