mirror of
https://github.com/ossrs/srs.git
synced 2025-02-14 20:31:56 +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) {
|
||||
printf("simple handshake failed.\n");
|
||||
return -1;
|
||||
goto rtmp_destroy;
|
||||
}
|
||||
printf("simple handshake success\n");
|
||||
|
||||
if (srs_connect_app(rtmp) != 0) {
|
||||
printf("connect vhost/app failed.\n");
|
||||
return -1;
|
||||
goto rtmp_destroy;
|
||||
}
|
||||
printf("connect vhost/app success\n");
|
||||
|
||||
if (srs_play_stream(rtmp) != 0) {
|
||||
printf("play stream failed.\n");
|
||||
return -1;
|
||||
goto rtmp_destroy;
|
||||
}
|
||||
printf("play stream success\n");
|
||||
|
||||
rtmp_destroy:
|
||||
srs_rtmp_destroy(rtmp);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -39,22 +39,23 @@ int main(int argc, char** argv)
|
|||
|
||||
if (srs_simple_handshake(rtmp) != 0) {
|
||||
printf("simple handshake failed.\n");
|
||||
return -1;
|
||||
goto rtmp_destroy;
|
||||
}
|
||||
printf("simple handshake success\n");
|
||||
|
||||
if (srs_connect_app(rtmp) != 0) {
|
||||
printf("connect vhost/app failed.\n");
|
||||
return -1;
|
||||
goto rtmp_destroy;
|
||||
}
|
||||
printf("connect vhost/app success\n");
|
||||
|
||||
if (srs_publish_stream(rtmp) != 0) {
|
||||
printf("publish stream failed.\n");
|
||||
return -1;
|
||||
goto rtmp_destroy;
|
||||
}
|
||||
printf("publish stream success\n");
|
||||
|
||||
rtmp_destroy:
|
||||
srs_rtmp_destroy(rtmp);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -39,17 +39,17 @@ struct Context
|
|||
{
|
||||
std::string url;
|
||||
SrsRtmpClient* rtmp;
|
||||
SimpleSocketStream* stream;
|
||||
SimpleSocketStream* skt;
|
||||
int stream_id;
|
||||
|
||||
Context() {
|
||||
rtmp = NULL;
|
||||
stream = NULL;
|
||||
skt = NULL;
|
||||
stream_id = 0;
|
||||
}
|
||||
virtual ~Context() {
|
||||
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){
|
||||
srs_assert(rtmp != NULL);
|
||||
Context* context = (Context*)rtmp;
|
||||
|
||||
srs_freep(context);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue