mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Add SrsAutoFreeH to release ptr with hooks. (#2880). v4.0.226
This commit is contained in:
parent
73d0ce1cee
commit
3881c4c77e
3 changed files with 18 additions and 6 deletions
|
@ -8,7 +8,9 @@ The changelog for SRS.
|
|||
|
||||
## SRS 4.0 Changelog
|
||||
|
||||
* v4.0, 2022-01-14, Support api_port to specify the WebRTC API port. v4.0.224
|
||||
* v4.0, 2022-01-13, For [#2880](https://github.com/ossrs/srs/pull/2880): Add SrsAutoFreeH to release ptr with hooks. (#2880). v4.0.226
|
||||
* v4.0, 2022-01-13, Support api_port to specify the WebRTC API port. v4.0.226
|
||||
* v4.0, 2022-01-13, Support api_port to specify the WebRTC API port. v4.0.224
|
||||
* v4.0, 2022-01-13, Merge [#2873](https://github.com/ossrs/srs/pull/2873): LiveSource: Refine fetch for external exposed interface. (#2873). v4.0.223
|
||||
* v4.0, 2022-01-13, Add conf/lighthouse.conf for LightHouse. v4.0.222
|
||||
* v4.0, 2022-01-12, Refine the running homepage. v4.0.221
|
||||
|
|
|
@ -30,13 +30,16 @@
|
|||
// where the char* pstr = new char[size].
|
||||
// To delete object.
|
||||
#define SrsAutoFree(className, instance) \
|
||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false)
|
||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false, NULL)
|
||||
// To delete array.
|
||||
#define SrsAutoFreeA(className, instance) \
|
||||
impl_SrsAutoFree<className> _auto_free_array_##instance(&instance, true, false)
|
||||
impl_SrsAutoFree<className> _auto_free_array_##instance(&instance, true, false, NULL)
|
||||
// Use free instead of delete.
|
||||
#define SrsAutoFreeF(className, instance) \
|
||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, true)
|
||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, true, NULL)
|
||||
// Use hook instead of delete.
|
||||
#define SrsAutoFreeH(className, instance, hook) \
|
||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false, hook)
|
||||
// The template implementation.
|
||||
template<class T>
|
||||
class impl_SrsAutoFree
|
||||
|
@ -45,11 +48,16 @@ private:
|
|||
T** ptr;
|
||||
bool is_array;
|
||||
bool _use_free;
|
||||
void (*_hook)(T*);
|
||||
public:
|
||||
impl_SrsAutoFree(T** p, bool array, bool use_free) {
|
||||
// If use_free, use free(void*) to release the p.
|
||||
// If specified hook, use hook(p) to release it.
|
||||
// Use delete to release p, or delete[] if p is an array.
|
||||
impl_SrsAutoFree(T** p, bool array, bool use_free, void (*hook)(T*)) {
|
||||
ptr = p;
|
||||
is_array = array;
|
||||
_use_free = use_free;
|
||||
_hook = hook;
|
||||
}
|
||||
|
||||
virtual ~impl_SrsAutoFree() {
|
||||
|
@ -59,6 +67,8 @@ public:
|
|||
|
||||
if (_use_free) {
|
||||
free(*ptr);
|
||||
} else if (_hook) {
|
||||
_hook(*ptr);
|
||||
} else {
|
||||
if (is_array) {
|
||||
delete[] *ptr;
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
|
||||
#define VERSION_MAJOR 4
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 225
|
||||
#define VERSION_REVISION 226
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue