winlin

fix ffmpeg log fd leak, always close log_fd. 0.9.94

@@ -64,8 +64,6 @@ SrsFFMPEG::SrsFFMPEG(std::string ffmpeg_bin) @@ -64,8 +64,6 @@ SrsFFMPEG::SrsFFMPEG(std::string ffmpeg_bin)
64 abitrate = 0; 64 abitrate = 0;
65 asample_rate = 0; 65 asample_rate = 0;
66 achannels = 0; 66 achannels = 0;
67 -  
68 - log_fd = -1;  
69 } 67 }
70 68
71 SrsFFMPEG::~SrsFFMPEG() 69 SrsFFMPEG::~SrsFFMPEG()
@@ -375,6 +373,7 @@ int SrsFFMPEG::start() @@ -375,6 +373,7 @@ int SrsFFMPEG::start()
375 // child process: ffmpeg encoder engine. 373 // child process: ffmpeg encoder engine.
376 if (pid == 0) { 374 if (pid == 0) {
377 // redirect logs to file. 375 // redirect logs to file.
  376 + int log_fd = -1;
378 int flags = O_CREAT|O_WRONLY|O_APPEND; 377 int flags = O_CREAT|O_WRONLY|O_APPEND;
379 mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; 378 mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH;
380 if ((log_fd = ::open(log_file.c_str(), flags, mode)) < 0) { 379 if ((log_fd = ::open(log_file.c_str(), flags, mode)) < 0) {
@@ -392,6 +391,8 @@ int SrsFFMPEG::start() @@ -392,6 +391,8 @@ int SrsFFMPEG::start()
392 srs_error("dup2 encoder file failed. ret=%d", ret); 391 srs_error("dup2 encoder file failed. ret=%d", ret);
393 return ret; 392 return ret;
394 } 393 }
  394 + // close log fd
  395 + ::close(log_fd);
395 // close other fds 396 // close other fds
396 // TODO: do in right way. 397 // TODO: do in right way.
397 for (int i = 3; i < 1024; i++) { 398 for (int i = 3; i < 1024; i++) {
@@ -456,11 +457,6 @@ int SrsFFMPEG::cycle() @@ -456,11 +457,6 @@ int SrsFFMPEG::cycle()
456 457
457 void SrsFFMPEG::stop() 458 void SrsFFMPEG::stop()
458 { 459 {
459 - if (log_fd > 0) {  
460 - ::close(log_fd);  
461 - log_fd = -1;  
462 - }  
463 -  
464 if (!started) { 460 if (!started) {
465 return; 461 return;
466 } 462 }
@@ -48,7 +48,6 @@ private: @@ -48,7 +48,6 @@ private:
48 pid_t pid; 48 pid_t pid;
49 private: 49 private:
50 std::string log_file; 50 std::string log_file;
51 - int log_fd;  
52 private: 51 private:
53 std::string ffmpeg; 52 std::string ffmpeg;
54 std::string _iparams; 53 std::string _iparams;
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "93" 34 +#define VERSION_REVISION "94"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "srs" 37 #define RTMP_SIG_SRS_KEY "srs"