| File: | cppu/source/threadpool/threadident.cxx |
| Location: | line 91, column 5 |
| Description: | Access to field 'nRefCountOfCurrentId' results in a dereference of a null pointer (loaded from variable 'p') |
| 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 <stdio.h> | ||
| 21 | |||
| 22 | #include <list> | ||
| 23 | |||
| 24 | #include <osl/mutex.hxx> | ||
| 25 | #include <osl/thread.h> | ||
| 26 | #include <osl/diagnose.h> | ||
| 27 | |||
| 28 | #include <rtl/process.h> | ||
| 29 | #include <rtl/byteseq.hxx> | ||
| 30 | |||
| 31 | #include <uno/threadpool.h> | ||
| 32 | |||
| 33 | #include "current.hxx" | ||
| 34 | |||
| 35 | |||
| 36 | using namespace ::std; | ||
| 37 | using namespace ::osl; | ||
| 38 | using namespace ::rtl; | ||
| 39 | using namespace ::cppu; | ||
| 40 | |||
| 41 | |||
| 42 | static inline void createLocalId( sal_Sequence **ppThreadId ) | ||
| 43 | { | ||
| 44 | rtl_byte_sequence_constructNoDefault( ppThreadId , 4 + 16 ); | ||
| 45 | sal_uInt32 id = osl_getThreadIdentifier(0); | ||
| 46 | (*ppThreadId)->elements[0] = id & 0xFF; | ||
| 47 | (*ppThreadId)->elements[1] = (id >> 8) & 0xFF; | ||
| 48 | (*ppThreadId)->elements[2] = (id >> 16) & 0xFF; | ||
| 49 | (*ppThreadId)->elements[3] = (id >> 24) & 0xFF; | ||
| 50 | rtl_getGlobalProcessId( (sal_uInt8 * ) &( (*ppThreadId)->elements[4]) ); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | extern "C" void SAL_CALL | ||
| 55 | uno_getIdOfCurrentThread( sal_Sequence **ppThreadId ) | ||
| 56 | SAL_THROW_EXTERN_C()throw () | ||
| 57 | { | ||
| 58 | IdContainer * p = getIdContainer(); | ||
| 59 | if( ! p->bInit ) | ||
| 60 | { | ||
| 61 | // first time, that the thread enters the bridge | ||
| 62 | createLocalId( ppThreadId ); | ||
| 63 | |||
| 64 | // TODO | ||
| 65 | // note : this is a leak ! | ||
| 66 | p->pLocalThreadId = *ppThreadId; | ||
| 67 | p->pCurrentId = *ppThreadId; | ||
| 68 | p->nRefCountOfCurrentId = 1; | ||
| 69 | rtl_byte_sequence_acquire( p->pLocalThreadId ); | ||
| 70 | rtl_byte_sequence_acquire( p->pCurrentId ); | ||
| 71 | p->bInit = sal_True((sal_Bool)1); | ||
| 72 | } | ||
| 73 | else | ||
| 74 | { | ||
| 75 | p->nRefCountOfCurrentId ++; | ||
| 76 | if( *ppThreadId ) | ||
| 77 | { | ||
| 78 | rtl_byte_sequence_release( *ppThreadId ); | ||
| 79 | } | ||
| 80 | *ppThreadId = p->pCurrentId; | ||
| 81 | rtl_byte_sequence_acquire( *ppThreadId ); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | extern "C" void SAL_CALL uno_releaseIdFromCurrentThread() | ||
| 87 | SAL_THROW_EXTERN_C()throw () | ||
| 88 | { | ||
| 89 | IdContainer *p = getIdContainer(); | ||
| 90 | OSL_ASSERT( p )do { if (true && (!(p))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/threadpool/threadident.cxx" ":" "90" ": "), "OSL_ASSERT: %s", "p"); } } while (false); | ||
| 91 | OSL_ASSERT( p->nRefCountOfCurrentId )do { if (true && (!(p->nRefCountOfCurrentId))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/cppu/source/threadpool/threadident.cxx" ":" "91" ": "), "OSL_ASSERT: %s", "p->nRefCountOfCurrentId" ); } } while (false); | ||
Within the expansion of the macro 'OSL_ASSERT':
| |||
| 92 | |||
| 93 | p->nRefCountOfCurrentId --; | ||
| 94 | if( ! p->nRefCountOfCurrentId && (p->pLocalThreadId != p->pCurrentId) ) | ||
| 95 | { | ||
| 96 | rtl_byte_sequence_assign( &(p->pCurrentId) , p->pLocalThreadId ); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | extern "C" sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId ) | ||
| 101 | SAL_THROW_EXTERN_C()throw () | ||
| 102 | { | ||
| 103 | IdContainer *p = getIdContainer(); | ||
| 104 | if( ! p->bInit ) | ||
| 105 | { | ||
| 106 | p->pLocalThreadId = 0; | ||
| 107 | createLocalId( &(p->pLocalThreadId) ); | ||
| 108 | p->nRefCountOfCurrentId = 1; | ||
| 109 | p->pCurrentId = pThreadId; | ||
| 110 | rtl_byte_sequence_acquire( p->pCurrentId ); | ||
| 111 | p->bInit = sal_True((sal_Bool)1); | ||
| 112 | } | ||
| 113 | else | ||
| 114 | { | ||
| 115 | OSL_ASSERT( 0 == p->nRefCountOfCurrentId )do { if (true && (!(0 == p->nRefCountOfCurrentId)) ) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/cppu/source/threadpool/threadident.cxx" ":" "115" ": "), "OSL_ASSERT: %s", "0 == p->nRefCountOfCurrentId" ); } } while (false); | ||
| 116 | if( 0 == p->nRefCountOfCurrentId ) | ||
| 117 | { | ||
| 118 | rtl_byte_sequence_assign(&( p->pCurrentId ), pThreadId ); | ||
| 119 | p->nRefCountOfCurrentId ++; | ||
| 120 | } | ||
| 121 | else | ||
| 122 | { | ||
| 123 | return sal_False((sal_Bool)0); | ||
| 124 | } | ||
| 125 | |||
| 126 | } | ||
| 127 | return sal_True((sal_Bool)1); | ||
| 128 | } | ||
| 129 | |||
| 130 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |