Fixed linux listenserver startup problems
Fixed multiple buffer overruns and memory leaks.
This commit is contained in:
parent
c5031315bf
commit
74f1ab866b
29 changed files with 371 additions and 254 deletions
52
ext/crlib/cr-memory.h
Normal file
52
ext/crlib/cr-memory.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
|
||||
// Copyright © 2004-2020 YaPB Project <yapb@jeefo.net>.
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <crlib/cr-basic.h>
|
||||
#include <crlib/cr-movable.h>
|
||||
#include <crlib/cr-platform.h>
|
||||
|
||||
// provide placment new to avoid stdc++ <new> header
|
||||
inline void *operator new (const size_t, void *ptr) noexcept {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
CR_NAMESPACE_BEGIN
|
||||
|
||||
// internal memory manager
|
||||
class Memory final {
|
||||
public:
|
||||
Memory () = default;
|
||||
~Memory () = default;
|
||||
|
||||
public:
|
||||
template <typename T> static T *get (const size_t length = 1) {
|
||||
auto memory = reinterpret_cast <T *> (malloc (cr::max <size_t> (1u, length * sizeof (T))));
|
||||
|
||||
if (!memory) {
|
||||
plat.abort ();
|
||||
}
|
||||
return memory;
|
||||
}
|
||||
|
||||
template <typename T> static void release (T *memory) {
|
||||
free (memory);
|
||||
memory = nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename T, typename ...Args> static void construct (T *memory, Args &&...args) {
|
||||
new (memory) T (cr::forward <Args> (args)...);
|
||||
}
|
||||
|
||||
template <typename T> static void destruct (T *memory) {
|
||||
memory->~T ();
|
||||
}
|
||||
};
|
||||
|
||||
CR_NAMESPACE_END
|
||||
Loading…
Add table
Add a link
Reference in a new issue