mirror of
https://github.com/holub/mame
synced 2025-06-30 16:00:01 +03:00
Fix many valgrind Mismatched free() / delete / delete [] errors
This commit is contained in:
parent
fff33e90f8
commit
cb231cea0a
@ -10,15 +10,20 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef __COREALLOC_H__
|
#ifndef MAME_LIB_UTIL_COREALLOC_H
|
||||||
#define __COREALLOC_H__
|
#define MAME_LIB_UTIL_COREALLOC_H
|
||||||
|
|
||||||
|
#include "osdcore.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstring>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <memory>
|
|
||||||
#include "osdcore.h"
|
|
||||||
|
|
||||||
|
|
||||||
//**************************************************************************
|
//**************************************************************************
|
||||||
@ -35,21 +40,21 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename _Tp, typename... _Args>
|
template<typename T, typename... Params>
|
||||||
inline _Tp* global_alloc_clear(_Args&&... __args)
|
inline T* global_alloc_clear(Params &&... args)
|
||||||
{
|
{
|
||||||
unsigned char * ptr = new unsigned char[sizeof(_Tp)]; // allocate memory
|
void *const ptr = ::operator new(sizeof(T)); // allocate memory
|
||||||
memset(ptr, 0, sizeof(_Tp));
|
std::memset(ptr, 0, sizeof(T));
|
||||||
return new(ptr) _Tp(std::forward<_Args>(__args)...);
|
return new(ptr) T(std::forward<Params>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename T>
|
||||||
inline _Tp* global_alloc_array_clear(size_t __num)
|
inline T* global_alloc_array_clear(std::size_t num)
|
||||||
{
|
{
|
||||||
auto size = sizeof(_Tp) * __num;
|
auto const size = sizeof(T) * num;
|
||||||
unsigned char* ptr = new unsigned char[size]; // allocate memory
|
void *const ptr = new unsigned char[size]; // allocate memory
|
||||||
memset(ptr, 0, size);
|
std::memset(ptr, 0, size);
|
||||||
return new(ptr) _Tp[__num]();
|
return new(ptr) T[num]();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -104,4 +109,4 @@ inline typename _MakeUniqClear<_Tp>::__array make_unique_clear(size_t __num)
|
|||||||
template<typename _Tp, typename... _Args>
|
template<typename _Tp, typename... _Args>
|
||||||
inline typename _MakeUniqClear<_Tp>::__invalid_type make_unique_clear(_Args&&...) = delete;
|
inline typename _MakeUniqClear<_Tp>::__invalid_type make_unique_clear(_Args&&...) = delete;
|
||||||
|
|
||||||
#endif /* __COREALLOC_H__ */
|
#endif // MAME_LIB_UTIL_COREALLOC_H
|
||||||
|
Loading…
Reference in New Issue
Block a user