UniquePtr: Support SrsUniquePtr to replace SrsAutoFree. v6.0.136#4109
UniquePtr: Support SrsUniquePtr to replace SrsAutoFree. v6.0.136#4109winlinvip merged 8 commits intoossrs:developfrom
Conversation
| #ifndef SRS_CORE_DEPRECATED_HPP | ||
| #define SRS_CORE_DEPRECATED_HPP | ||
|
|
||
| #include <srs_core.hpp> |
There was a problem hiding this comment.
this include header,srs_core.hpp, is useless, can be removed.
There was a problem hiding this comment.
I want to make sure the first included file is this one.
Won't fix.
| // SPDX-License-Identifier: MIT | ||
| // | ||
|
|
||
| #include <srs_core_deprecated.hpp> |
There was a problem hiding this comment.
I don't know whether it's a code conventions or not, but an empty cpp, seems useless.
There was a problem hiding this comment.
It will cause the utest fail. Please file another PR if you want to remove it.
Won't fix.
ba2a4c6 to
96ad539
Compare
| // process all http messages. | ||
| err = process_requests(&last_req); | ||
| SrsRequest* last_req_raw = NULL; | ||
| err = process_requests(&last_req_raw); |
There was a problem hiding this comment.
err need to freed and processed if it's not srs_success, otherwise err != srs_success would be a memory leak.
There was a problem hiding this comment.
The err is returned:
err = process_requests(&last_req_raw);
if ((r0 = on_disconnect(last_req.get())) != srs_success) {
err = srs_error_wrap(err, "on disconnect %s", srs_error_desc(r0).c_str());
srs_freep(r0);
}
return err;Won't fix.
| } | ||
|
|
||
| srs_assert(consumer); | ||
| srs_assert(consumer_raw); |
There was a problem hiding this comment.
consumer_raw will alway has value, no need to check with assert?
srs/trunk/src/app/srs_app_rtc_source.cpp
Lines 550 to 562 in baf22d0
There was a problem hiding this comment.
Not a bug or logic error.
Won't fix.
| // We must free it, should never use RTP packets to free it, | ||
| // because more than one RTP packet will refer to it. | ||
| SrsAutoFree(SrsRtpRawNALUs, raw); | ||
| SrsUniquePtr<SrsRtpRawNALUs> raw(raw_raw); |
There was a problem hiding this comment.
I would rather use a srs_freep(raw_raw) manually in this else scope to simple the code.
There was a problem hiding this comment.
Nop, it's used later:
SrsUniquePtr<SrsRtpRawNALUs> raw(raw_raw);
uint8_t header = raw->skip_first_byte();Won't fix.
| } | ||
| srs_assert(consumer); | ||
|
|
||
| srs_assert(consumer_raw); |
There was a problem hiding this comment.
consumer_raw always true here
There was a problem hiding this comment.
Not a bug or an error.
Won't fix.
To manage an object:
To manage an array of objects:
In fact, SrsUniquePtr is a limited subset of SrsAutoFree, mainly managing pointers and arrays. SrsUniquePtr is better than SrsAutoFree because it has the same API to standard unique ptr.
SrsAutoFree actually uses a pointer to a pointer, so it can be set to NULL, allowing the pointer's value to be changed later (this usage is different from SrsUniquePtr).
Additionally, SrsAutoFreeH can use specific release functions, which SrsUniquePtr does not support.
Co-authored-by: Jacob Su suzp1984@gmail.com