mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
use goto to free resource
This commit is contained in:
parent
feaf0c5e89
commit
b7a62ba131
3 changed files with 18 additions and 9 deletions
|
@ -39,22 +39,23 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (srs_simple_handshake(rtmp) != 0) {
|
if (srs_simple_handshake(rtmp) != 0) {
|
||||||
printf("simple handshake failed.\n");
|
printf("simple handshake failed.\n");
|
||||||
return -1;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("simple handshake success\n");
|
printf("simple handshake success\n");
|
||||||
|
|
||||||
if (srs_connect_app(rtmp) != 0) {
|
if (srs_connect_app(rtmp) != 0) {
|
||||||
printf("connect vhost/app failed.\n");
|
printf("connect vhost/app failed.\n");
|
||||||
return -1;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("connect vhost/app success\n");
|
printf("connect vhost/app success\n");
|
||||||
|
|
||||||
if (srs_play_stream(rtmp) != 0) {
|
if (srs_play_stream(rtmp) != 0) {
|
||||||
printf("play stream failed.\n");
|
printf("play stream failed.\n");
|
||||||
return -1;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("play stream success\n");
|
printf("play stream success\n");
|
||||||
|
|
||||||
|
rtmp_destroy:
|
||||||
srs_rtmp_destroy(rtmp);
|
srs_rtmp_destroy(rtmp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -39,22 +39,23 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (srs_simple_handshake(rtmp) != 0) {
|
if (srs_simple_handshake(rtmp) != 0) {
|
||||||
printf("simple handshake failed.\n");
|
printf("simple handshake failed.\n");
|
||||||
return -1;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("simple handshake success\n");
|
printf("simple handshake success\n");
|
||||||
|
|
||||||
if (srs_connect_app(rtmp) != 0) {
|
if (srs_connect_app(rtmp) != 0) {
|
||||||
printf("connect vhost/app failed.\n");
|
printf("connect vhost/app failed.\n");
|
||||||
return -1;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("connect vhost/app success\n");
|
printf("connect vhost/app success\n");
|
||||||
|
|
||||||
if (srs_publish_stream(rtmp) != 0) {
|
if (srs_publish_stream(rtmp) != 0) {
|
||||||
printf("publish stream failed.\n");
|
printf("publish stream failed.\n");
|
||||||
return -1;
|
goto rtmp_destroy;
|
||||||
}
|
}
|
||||||
printf("publish stream success\n");
|
printf("publish stream success\n");
|
||||||
|
|
||||||
|
rtmp_destroy:
|
||||||
srs_rtmp_destroy(rtmp);
|
srs_rtmp_destroy(rtmp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -39,17 +39,17 @@ struct Context
|
||||||
{
|
{
|
||||||
std::string url;
|
std::string url;
|
||||||
SrsRtmpClient* rtmp;
|
SrsRtmpClient* rtmp;
|
||||||
SimpleSocketStream* stream;
|
SimpleSocketStream* skt;
|
||||||
int stream_id;
|
int stream_id;
|
||||||
|
|
||||||
Context() {
|
Context() {
|
||||||
rtmp = NULL;
|
rtmp = NULL;
|
||||||
stream = NULL;
|
skt = NULL;
|
||||||
stream_id = 0;
|
stream_id = 0;
|
||||||
}
|
}
|
||||||
virtual ~Context() {
|
virtual ~Context() {
|
||||||
srs_freep(rtmp);
|
srs_freep(rtmp);
|
||||||
srs_freep(stream);
|
srs_freep(skt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,11 +66,18 @@ srs_rtmp_t srs_rtmp_create(const char* url){
|
||||||
void srs_rtmp_destroy(srs_rtmp_t rtmp){
|
void srs_rtmp_destroy(srs_rtmp_t rtmp){
|
||||||
srs_assert(rtmp != NULL);
|
srs_assert(rtmp != NULL);
|
||||||
Context* context = (Context*)rtmp;
|
Context* context = (Context*)rtmp;
|
||||||
|
|
||||||
srs_freep(context);
|
srs_freep(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
int srs_simple_handshake(srs_rtmp_t rtmp)
|
int srs_simple_handshake(srs_rtmp_t rtmp)
|
||||||
{
|
{
|
||||||
|
srs_assert(rtmp != NULL);
|
||||||
|
Context* context = (Context*)rtmp;
|
||||||
|
|
||||||
|
srs_freep(context->skt);
|
||||||
|
context->skt = new SimpleSocketStream();
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue