| File: | cppu/source/helper/purpenv/helper_purpenv_Mapping.cxx |
| Location: | line 148, column 9 |
| Description: | Dereference of null pointer (loaded from variable 'ppOut') |
| 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 | |
| 21 | #include "cppu/helper/purpenv/Mapping.hxx" |
| 22 | |
| 23 | #include "Proxy.hxx" |
| 24 | |
| 25 | #include "osl/interlck.h" |
| 26 | #include "uno/environment.hxx" |
| 27 | #include "uno/dispatcher.h" |
| 28 | #include "typelib/typedescription.h" |
| 29 | |
| 30 | |
| 31 | #ifdef debug |
| 32 | # define LOG_LIFECYCLE_cppu_helper_purpenv_Mapping |
| 33 | #endif |
| 34 | |
| 35 | #ifdef LOG_LIFECYCLE_cppu_helper_purpenv_Mapping |
| 36 | # include <iostream> |
| 37 | # define LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(x) x |
| 38 | |
| 39 | #else |
| 40 | # define LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(x) |
| 41 | |
| 42 | #endif |
| 43 | |
| 44 | |
| 45 | using namespace com::sun::star; |
| 46 | |
| 47 | |
| 48 | class Mapping : public uno_Mapping |
| 49 | { |
| 50 | uno::Environment m_from; |
| 51 | uno::Environment m_to; |
| 52 | |
| 53 | oslInterlockedCount m_nCount; |
| 54 | |
| 55 | cppu::helper::purpenv::ProbeFun * m_probeFun; |
| 56 | void * m_pContext; |
| 57 | |
| 58 | public: |
| 59 | explicit Mapping(uno_Environment * pFrom, |
| 60 | uno_Environment * pTo, |
| 61 | cppu::helper::purpenv::ProbeFun * probeFun, |
| 62 | void * pProbeContext); |
| 63 | virtual ~Mapping(void); |
| 64 | |
| 65 | void mapInterface( |
| 66 | uno_Interface ** ppOut, |
| 67 | uno_Interface * pUnoI, |
| 68 | typelib_InterfaceTypeDescription * pTypeDescr); |
| 69 | |
| 70 | void acquire(void); |
| 71 | void release(void); |
| 72 | }; |
| 73 | |
| 74 | static void SAL_CALL s_mapInterface( |
| 75 | uno_Mapping * puno_Mapping, |
| 76 | uno_Interface ** ppOut, |
| 77 | uno_Interface * pUnoI, |
| 78 | typelib_InterfaceTypeDescription * pTypeDescr ) |
| 79 | SAL_THROW_EXTERN_C()throw () |
| 80 | { |
| 81 | Mapping * pMapping = static_cast<Mapping *>(puno_Mapping); |
| 82 | pMapping->mapInterface(ppOut, pUnoI, pTypeDescr); |
| 83 | } |
| 84 | |
| 85 | extern "C" { |
| 86 | static void SAL_CALL s_acquire(uno_Mapping * puno_Mapping) |
| 87 | SAL_THROW_EXTERN_C()throw () |
| 88 | { |
| 89 | Mapping * pMapping = static_cast<Mapping *>(puno_Mapping); |
| 90 | pMapping->acquire(); |
| 91 | } |
| 92 | |
| 93 | static void SAL_CALL s_release(uno_Mapping * puno_Mapping) |
| 94 | SAL_THROW_EXTERN_C()throw () |
| 95 | { |
| 96 | Mapping * pMapping = static_cast<Mapping * >(puno_Mapping); |
| 97 | pMapping->release(); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | static void s_getIdentifier_v(va_list * pParam) |
| 102 | { |
| 103 | uno_ExtEnvironment * pEnv = va_arg(*pParam, uno_ExtEnvironment *)__builtin_va_arg(*pParam, uno_ExtEnvironment *); |
| 104 | rtl_uString ** ppOid = va_arg(*pParam, rtl_uString **)__builtin_va_arg(*pParam, rtl_uString **); |
| 105 | uno_Interface * pUnoI = va_arg(*pParam, uno_Interface *)__builtin_va_arg(*pParam, uno_Interface *); |
| 106 | |
| 107 | pEnv->getObjectIdentifier(pEnv, ppOid, pUnoI); |
| 108 | } |
| 109 | |
| 110 | static void SAL_CALL s_free(uno_Mapping * puno_Mapping) |
| 111 | SAL_THROW_EXTERN_C()throw () |
| 112 | { |
| 113 | Mapping * pMapping = static_cast<Mapping *>(puno_Mapping); |
| 114 | delete pMapping; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | Mapping::Mapping(uno_Environment * pFrom, |
| 119 | uno_Environment * pTo, |
| 120 | cppu::helper::purpenv::ProbeFun * probeFun, |
| 121 | void * pProbeContext |
| 122 | ) SAL_THROW(()) |
| 123 | : m_from (pFrom), |
| 124 | m_to (pTo), |
| 125 | m_nCount (1), |
| 126 | m_probeFun(probeFun), |
| 127 | m_pContext(pProbeContext) |
| 128 | { |
| 129 | LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(fprintf(stderr, "LIFE: %s -> %p\n", "Mapping::Mapping(uno_Environment * pFrom, uno_Environment * pTo) SAL_THROW(())", this)); |
| 130 | |
| 131 | uno_Mapping::acquire = s_acquire; |
| 132 | uno_Mapping::release = s_release; |
| 133 | uno_Mapping::mapInterface = (uno_MapInterfaceFunc)s_mapInterface; |
| 134 | } |
| 135 | |
| 136 | Mapping::~Mapping(void) |
| 137 | { |
| 138 | LOG_LIFECYCLE_cppu_helper_purpenv_Mapping_emit(fprintf(stderr, "LIFE: %s -> %p\n", "Mapping::~Mapping(void)", this)); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | void Mapping::mapInterface( |
| 143 | uno_Interface ** ppOut, |
| 144 | uno_Interface * pUnoI, |
| 145 | typelib_InterfaceTypeDescription * pTypeDescr) |
| 146 | { |
| 147 | OSL_ASSERT(ppOut && pTypeDescr)do { if (true && (!(ppOut && pTypeDescr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/helper/purpenv/helper_purpenv_Mapping.cxx" ":" "147" ": "), "OSL_ASSERT: %s", "ppOut && pTypeDescr" ); } } while (false); |
| 148 | if (*ppOut) |
Dereference of null pointer (loaded from variable 'ppOut') | |
| 149 | { |
| 150 | (*ppOut)->release(*ppOut); |
| 151 | *ppOut = 0; |
| 152 | } |
| 153 | |
| 154 | if (!pUnoI) |
| 155 | return; |
| 156 | |
| 157 | // get object id of uno interface to be wrapped |
| 158 | // need to enter environment because of potential "queryInterface" call |
| 159 | rtl_uString * pOId = 0; |
| 160 | uno_Environment_invoke(m_from.get(), s_getIdentifier_v, m_from.get(), &pOId, pUnoI); |
| 161 | OSL_ASSERT(pOId)do { if (true && (!(pOId))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/helper/purpenv/helper_purpenv_Mapping.cxx" ":" "161" ": "), "OSL_ASSERT: %s", "pOId"); } } while (false ); |
| 162 | |
| 163 | // try to get any known interface from target environment |
| 164 | m_to.get()->pExtEnv->getRegisteredInterface(m_to.get()->pExtEnv, (void **)ppOut, pOId, pTypeDescr); |
| 165 | |
| 166 | if (!*ppOut) // not yet there, register new proxy interface |
| 167 | { |
| 168 | // try to publish a new proxy (ref count initially 1) |
| 169 | uno_Interface * pProxy = new Proxy(this, |
| 170 | m_from.get(), |
| 171 | m_to.get(), |
| 172 | pUnoI, |
| 173 | pTypeDescr, |
| 174 | pOId, |
| 175 | m_probeFun, |
| 176 | m_pContext); |
| 177 | |
| 178 | // proxy may be exchanged during registration |
| 179 | m_to.get()->pExtEnv->registerProxyInterface(m_to.get()->pExtEnv, |
| 180 | (void **)&pProxy, |
| 181 | Proxy_free, |
| 182 | pOId, |
| 183 | pTypeDescr); |
| 184 | |
| 185 | *ppOut = pProxy; |
| 186 | } |
| 187 | |
| 188 | rtl_uString_release(pOId); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | void Mapping::acquire() SAL_THROW(()) |
| 193 | { |
| 194 | if (osl_incrementInterlockedCount(&m_nCount) == 1) |
| 195 | { |
| 196 | uno_Mapping * pMapping = this; |
| 197 | |
| 198 | ::uno_registerMapping(&pMapping, s_free, m_from.get(), m_to.get(), NULL__null); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | void Mapping::release() SAL_THROW(()) |
| 203 | { |
| 204 | if (osl_decrementInterlockedCount(&m_nCount) == 0) |
| 205 | ::uno_revokeMapping(this); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | namespace cppu { namespace helper { namespace purpenv { |
| 210 | |
| 211 | void createMapping(uno_Mapping ** ppMapping, |
| 212 | uno_Environment * pFrom, |
| 213 | uno_Environment * pTo, |
| 214 | ProbeFun * probeFun, |
| 215 | void * pContext |
| 216 | ) |
| 217 | { |
| 218 | *ppMapping = new Mapping(pFrom, pTo, probeFun, pContext); |
| 219 | |
| 220 | ::uno_registerMapping(ppMapping, s_free, pFrom, pTo, NULL__null); |
| 221 | } |
| 222 | |
| 223 | }}} |
| 224 | |
| 225 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |