Skip to content

Commit 80433fa

Browse files
committed
It's wrong to allocate memory with 'new' and deallocate with 'free'.
1 parent 2dff3de commit 80433fa

File tree

6 files changed

+9
-46
lines changed

6 files changed

+9
-46
lines changed

src/Layers/xrRenderDX10/StateManager/dx10State.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ HRESULT dx10State::Apply()
7878
void dx10State::Release()
7979
{
8080
dx10State* pState = this;
81-
xr_delete<dx10State>(pState);
81+
xr_delete/*<dx10State>*/(pState);
8282
}
8383

8484
void dx10State::InitSamplers(tSamplerHArray& SamplerArray, SimulatorStates& state_code, int iBaseSamplerIndex)

src/xrCore/xrMemory.h

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,10 @@ extern XRCORE_API xrMemory Memory;
3131
#define CopyMemory(a, b, c) memcpy(a, b, c)
3232
#define FillMemory(a, b, c) memset(a, c, b)
3333

34-
// delete
35-
36-
template <bool _is_pm, typename T>
37-
struct xr_special_free
38-
{
39-
IC void operator()(T*& ptr)
40-
{
41-
void* _real_ptr = dynamic_cast<void*>(ptr);
42-
ptr->~T();
43-
Memory.mem_free(_real_ptr);
44-
}
45-
};
46-
47-
template <typename T>
48-
struct xr_special_free<false, T>
49-
{
50-
IC void operator()(T*& ptr)
51-
{
52-
ptr->~T();
53-
Memory.mem_free(ptr);
54-
}
55-
};
56-
57-
template <class T>
58-
IC void xr_delete(T*& ptr)
59-
{
60-
if (ptr)
61-
{
62-
xr_special_free<std::is_polymorphic<T>::value, T>()(ptr);
63-
ptr = NULL;
64-
}
65-
}
66-
template <class T>
67-
IC void xr_delete(T* const& ptr)
68-
{
69-
if (ptr)
70-
{
71-
xr_special_free<std::is_polymorphic<T>::value, T>(ptr);
72-
const_cast<T*&>(ptr) = NULL;
73-
}
34+
#define xr_delete(x)\
35+
{\
36+
delete (x);\
37+
(x) = nullptr;\
7438
}
7539

7640
// generic "C"-like allocations/deallocations

src/xrEngine/PS_instance.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ class ENGINE_API CPS_Instance : public SpatialBase, public ScheduledBase, public
1111
{
1212
friend class IGame_Persistent;
1313

14-
template <bool _is_pm, typename T>
15-
friend struct xr_special_free;
16-
1714
private:
1815
bool m_destroy_on_game_load;
1916

src/xrGame/Actor_Network.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ void CActor::net_Destroy()
752752
if (m_pPhysicsShell)
753753
{
754754
m_pPhysicsShell->Deactivate();
755-
xr_delete<CPhysicsShell>(m_pPhysicsShell);
755+
xr_delete/*<CPhysicsShell>*/(m_pPhysicsShell);
756756
};
757757
m_pPhysics_support->in_NetDestroy();
758758

src/xrGame/UIGameDM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ void CUIGameDM::SetWarmUpCaption(LPCSTR str) { m_warm_up_caption->SetTextST(str)
136136
void CUIGameDM::SetVoteMessage(LPCSTR str)
137137
{
138138
if (!str)
139+
{
139140
xr_delete(m_voteStatusWnd);
141+
}
140142
else
141143
{
142144
if (!m_voteStatusWnd)

src/xrPhysics/PHShellActivate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void CPHShell::Deactivate()
231231
{
232232
VERIFY(PhysicsRefObject());
233233
PhysicsRefObject()->ObjectProcessingDeactivate();
234-
xr_delete<CPhysicsShellAnimator>(m_pPhysicsShellAnimatorC);
234+
xr_delete/*<CPhysicsShellAnimator>*/(m_pPhysicsShellAnimatorC);
235235
}
236236

237237
if (!isActive())

0 commit comments

Comments
 (0)