libavformat/mpegtsenc.c:497: error: Null Dereference
  pointer `pcr_st` last assigned on line 393 could be null and is dereferenced at line 497, column 13.

libavformat/mpegtsenc.c:388:1: start of procedure mpegts_write_header()
386. }
387. 
388. static int mpegts_write_header(AVFormatContext *s)
     ^
389. {
390.     MpegTSWrite *ts = s->priv_data;

libavformat/mpegtsenc.c:390:5: 
388. static int mpegts_write_header(AVFormatContext *s)
389. {
390.     MpegTSWrite *ts = s->priv_data;
         ^
391.     MpegTSWriteStream *ts_st;
392.     MpegTSService *service;

libavformat/mpegtsenc.c:393:5: 
391.     MpegTSWriteStream *ts_st;
392.     MpegTSService *service;
393.     AVStream *st, *pcr_st = NULL;
         ^
394.     AVMetadataTag *title;
395.     int i, j;

libavformat/mpegtsenc.c:399:5: 
397.     int *pids;
398. 
399.     ts->tsid = DEFAULT_TSID;
         ^
400.     ts->onid = DEFAULT_ONID;
401.     /* allocate a single DVB service */

libavformat/mpegtsenc.c:400:5: 
398. 
399.     ts->tsid = DEFAULT_TSID;
400.     ts->onid = DEFAULT_ONID;
         ^
401.     /* allocate a single DVB service */
402.     title = av_metadata_get(s->metadata, "title", NULL, 0);

libavformat/mpegtsenc.c:402:5: Skipping av_metadata_get(): empty list of specs
400.     ts->onid = DEFAULT_ONID;
401.     /* allocate a single DVB service */
402.     title = av_metadata_get(s->metadata, "title", NULL, 0);
         ^
403.     service_name = title ? title->value : DEFAULT_SERVICE_NAME;
404.     service = mpegts_add_service(ts, DEFAULT_SID,

libavformat/mpegtsenc.c:403:20: Condition is false
401.     /* allocate a single DVB service */
402.     title = av_metadata_get(s->metadata, "title", NULL, 0);
403.     service_name = title ? title->value : DEFAULT_SERVICE_NAME;
                        ^
404.     service = mpegts_add_service(ts, DEFAULT_SID,
405.                                  DEFAULT_PROVIDER_NAME, service_name);

libavformat/mpegtsenc.c:403:5: 
401.     /* allocate a single DVB service */
402.     title = av_metadata_get(s->metadata, "title", NULL, 0);
403.     service_name = title ? title->value : DEFAULT_SERVICE_NAME;
         ^
404.     service = mpegts_add_service(ts, DEFAULT_SID,
405.                                  DEFAULT_PROVIDER_NAME, service_name);

libavformat/mpegtsenc.c:404:5: Skipping mpegts_add_service(): empty list of specs
402.     title = av_metadata_get(s->metadata, "title", NULL, 0);
403.     service_name = title ? title->value : DEFAULT_SERVICE_NAME;
404.     service = mpegts_add_service(ts, DEFAULT_SID,
         ^
405.                                  DEFAULT_PROVIDER_NAME, service_name);
406.     service->pmt.write_packet = section_write_packet;

libavformat/mpegtsenc.c:406:5: 
404.     service = mpegts_add_service(ts, DEFAULT_SID,
405.                                  DEFAULT_PROVIDER_NAME, service_name);
406.     service->pmt.write_packet = section_write_packet;
         ^
407.     service->pmt.opaque = s;
408.     service->pmt.cc = 15;

libavformat/mpegtsenc.c:407:5: 
405.                                  DEFAULT_PROVIDER_NAME, service_name);
406.     service->pmt.write_packet = section_write_packet;
407.     service->pmt.opaque = s;
         ^
408.     service->pmt.cc = 15;
409. 

libavformat/mpegtsenc.c:408:5: 
406.     service->pmt.write_packet = section_write_packet;
407.     service->pmt.opaque = s;
408.     service->pmt.cc = 15;
         ^
409. 
410.     ts->pat.pid = PAT_PID;

libavformat/mpegtsenc.c:410:5: 
408.     service->pmt.cc = 15;
409. 
410.     ts->pat.pid = PAT_PID;
         ^
411.     ts->pat.cc = 15; // Initialize at 15 so that it wraps and be equal to 0 for the first packet we write
412.     ts->pat.write_packet = section_write_packet;

libavformat/mpegtsenc.c:411:5: 
409. 
410.     ts->pat.pid = PAT_PID;
411.     ts->pat.cc = 15; // Initialize at 15 so that it wraps and be equal to 0 for the first packet we write
         ^
412.     ts->pat.write_packet = section_write_packet;
413.     ts->pat.opaque = s;

libavformat/mpegtsenc.c:412:5: 
410.     ts->pat.pid = PAT_PID;
411.     ts->pat.cc = 15; // Initialize at 15 so that it wraps and be equal to 0 for the first packet we write
412.     ts->pat.write_packet = section_write_packet;
         ^
413.     ts->pat.opaque = s;
414. 

libavformat/mpegtsenc.c:413:5: 
411.     ts->pat.cc = 15; // Initialize at 15 so that it wraps and be equal to 0 for the first packet we write
412.     ts->pat.write_packet = section_write_packet;
413.     ts->pat.opaque = s;
         ^
414. 
415.     ts->sdt.pid = SDT_PID;

libavformat/mpegtsenc.c:415:5: 
413.     ts->pat.opaque = s;
414. 
415.     ts->sdt.pid = SDT_PID;
         ^
416.     ts->sdt.cc = 15;
417.     ts->sdt.write_packet = section_write_packet;

libavformat/mpegtsenc.c:416:5: 
414. 
415.     ts->sdt.pid = SDT_PID;
416.     ts->sdt.cc = 15;
         ^
417.     ts->sdt.write_packet = section_write_packet;
418.     ts->sdt.opaque = s;

libavformat/mpegtsenc.c:417:5: 
415.     ts->sdt.pid = SDT_PID;
416.     ts->sdt.cc = 15;
417.     ts->sdt.write_packet = section_write_packet;
         ^
418.     ts->sdt.opaque = s;
419. 

libavformat/mpegtsenc.c:418:5: 
416.     ts->sdt.cc = 15;
417.     ts->sdt.write_packet = section_write_packet;
418.     ts->sdt.opaque = s;
         ^
419. 
420.     pids = av_malloc(s->nb_streams * sizeof(*pids));

libavformat/mpegtsenc.c:420:5: 
418.     ts->sdt.opaque = s;
419. 
420.     pids = av_malloc(s->nb_streams * sizeof(*pids));
         ^
421.     if (!pids)
422.         return AVERROR(ENOMEM);

libavutil/mem.c:64:1: start of procedure av_malloc()
  62.    linker will do it automatically. */
  63. 
  64. void *av_malloc(FF_INTERNAL_MEM_TYPE size)
      ^
  65. {
  66.     void *ptr = NULL;

libavutil/mem.c:66:5: 
  64. void *av_malloc(FF_INTERNAL_MEM_TYPE size)
  65. {
  66.     void *ptr = NULL;
          ^
  67. #if CONFIG_MEMALIGN_HACK
  68.     long diff;

libavutil/mem.c:72:8: Taking false branch
  70. 
  71.     /* let's disallow possible ambiguous cases */
  72.     if(size > (INT_MAX-16) )
             ^
  73.         return NULL;
  74. 

libavutil/mem.c:83:9: Taking false branch
  81.     ((char*)ptr)[-1]= diff;
  82. #elif HAVE_POSIX_MEMALIGN
  83.     if (posix_memalign(&ptr,16,size))
              ^
  84.         ptr = NULL;
  85. #elif HAVE_MEMALIGN

libavutil/mem.c:116:5: 
  114.     ptr = malloc(size);
  115. #endif
  116.     return ptr;
           ^
  117. }
  118. 

libavutil/mem.c:117:1: return from a call to av_malloc
  115. #endif
  116.     return ptr;
  117. }
       ^
  118. 
  119. void *av_realloc(void *ptr, FF_INTERNAL_MEM_TYPE size)

libavformat/mpegtsenc.c:421:10: Taking false branch
419. 
420.     pids = av_malloc(s->nb_streams * sizeof(*pids));
421.     if (!pids)
              ^
422.         return AVERROR(ENOMEM);
423. 

libavformat/mpegtsenc.c:425:9: 
423. 
424.     /* assign pids to each stream */
425.     for(i = 0;i < s->nb_streams; i++) {
             ^
426.         st = s->streams[i];
427.         ts_st = av_mallocz(sizeof(MpegTSWriteStream));

libavformat/mpegtsenc.c:425:15: Loop condition is false. Leaving loop
423. 
424.     /* assign pids to each stream */
425.     for(i = 0;i < s->nb_streams; i++) {
                   ^
426.         st = s->streams[i];
427.         ts_st = av_mallocz(sizeof(MpegTSWriteStream));

libavformat/mpegtsenc.c:473:5: 
471.     }
472. 
473.     av_free(pids);
         ^
474. 
475.     /* if no video stream, use the first stream as PCR */

libavutil/mem.c:139:1: start of procedure av_free()
  137. }
  138. 
  139. void av_free(void *ptr)
       ^
  140. {
  141.     /* XXX: this test should not be needed on most libcs */

libavutil/mem.c:142:9: Taking true branch
  140. {
  141.     /* XXX: this test should not be needed on most libcs */
  142.     if (ptr)
               ^
  143. #if CONFIG_MEMALIGN_HACK
  144.         free((char*)ptr - ((char*)ptr)[-1]);

libavutil/mem.c:146:9: 
  144.         free((char*)ptr - ((char*)ptr)[-1]);
  145. #else
  146.         free(ptr);
               ^
  147. #endif
  148. }

libavutil/mem.c:142:5: 
  140. {
  141.     /* XXX: this test should not be needed on most libcs */
  142.     if (ptr)
           ^
  143. #if CONFIG_MEMALIGN_HACK
  144.         free((char*)ptr - ((char*)ptr)[-1]);

libavutil/mem.c:148:1: return from a call to av_free
  146.         free(ptr);
  147. #endif
  148. }
       ^
  149. 
  150. void av_freep(void *arg)

libavformat/mpegtsenc.c:476:9: Taking false branch
474. 
475.     /* if no video stream, use the first stream as PCR */
476.     if (service->pcr_pid == 0x1fff && s->nb_streams > 0) {
             ^
477.         pcr_st = s->streams[0];
478.         ts_st = pcr_st->priv_data;

libavformat/mpegtsenc.c:482:20: Condition is true
480.     }
481. 
482.     ts->mux_rate = s->mux_rate ? s->mux_rate : 1;
                        ^
483. 
484.     if (ts->mux_rate > 1) {

libavformat/mpegtsenc.c:482:5: 
480.     }
481. 
482.     ts->mux_rate = s->mux_rate ? s->mux_rate : 1;
         ^
483. 
484.     if (ts->mux_rate > 1) {

libavformat/mpegtsenc.c:484:9: Taking false branch
482.     ts->mux_rate = s->mux_rate ? s->mux_rate : 1;
483. 
484.     if (ts->mux_rate > 1) {
             ^
485.         service->pcr_packet_period = (ts->mux_rate * PCR_RETRANS_TIME) /
486.             (TS_PACKET_SIZE * 8 * 1000);

libavformat/mpegtsenc.c:495:9: 
493.     } else {
494.         /* Arbitrary values, PAT/PMT could be written on key frames */
495.         ts->sdt_packet_period = 200;
             ^
496.         ts->pat_packet_period = 40;
497.         if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {

libavformat/mpegtsenc.c:496:9: 
494.         /* Arbitrary values, PAT/PMT could be written on key frames */
495.         ts->sdt_packet_period = 200;
496.         ts->pat_packet_period = 40;
             ^
497.         if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
498.             if (!pcr_st->codec->frame_size) {

libavformat/mpegtsenc.c:497:13: 
495.         ts->sdt_packet_period = 200;
496.         ts->pat_packet_period = 40;
497.         if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
                 ^
498.             if (!pcr_st->codec->frame_size) {
499.                 av_log(s, AV_LOG_WARNING, "frame size not set\n");
