libavformat/matroskaenc.c:310: error: Null Dereference
  pointer `entries` last assigned on line 304 could be null and is dereferenced at line 310, column 5.

libavformat/matroskaenc.c:295:1: start of procedure mkv_add_seekhead_entry()
293. }
294. 
295. static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid, uint64_t filepos)
     ^
296. {
297.     mkv_seekhead_entry *entries = seekhead->entries;

libavformat/matroskaenc.c:297:5: 
295. static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid, uint64_t filepos)
296. {
297.     mkv_seekhead_entry *entries = seekhead->entries;
         ^
298.     int err;
299. 

libavformat/matroskaenc.c:301:9: Taking true branch
299. 
300.     // don't store more elements than we reserved space for
301.     if (seekhead->max_entries > 0 && seekhead->max_entries <= seekhead->num_entries)
             ^
302.         return -1;
303. 

libavformat/matroskaenc.c:301:38: Taking false branch
299. 
300.     // don't store more elements than we reserved space for
301.     if (seekhead->max_entries > 0 && seekhead->max_entries <= seekhead->num_entries)
                                          ^
302.         return -1;
303. 

libavformat/matroskaenc.c:304:9: 
302.         return -1;
303. 
304.     if ((err = av_reallocp_array(&entries, seekhead->num_entries + 1,
             ^
305.                                  sizeof(*entries))) < 0) {
306.         seekhead->num_entries = 0;

libavutil/mem.c:146:1: start of procedure av_reallocp_array()
  144. }
  145. 
  146. int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
       ^
  147. {
  148.     void **ptrptr = ptr;

libavutil/mem.c:148:5: 
  146. int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
  147. {
  148.     void **ptrptr = ptr;
           ^
  149.     void *ret;
  150.     if (!size || nmemb >= INT_MAX / size)

libavutil/mem.c:150:10: Taking false branch
  148.     void **ptrptr = ptr;
  149.     void *ret;
  150.     if (!size || nmemb >= INT_MAX / size)
                ^
  151.         return AVERROR(ENOMEM);
  152.     if (!nmemb) {

libavutil/mem.c:150:18: Taking false branch
  148.     void **ptrptr = ptr;
  149.     void *ret;
  150.     if (!size || nmemb >= INT_MAX / size)
                        ^
  151.         return AVERROR(ENOMEM);
  152.     if (!nmemb) {

libavutil/mem.c:152:10: Taking true branch
  150.     if (!size || nmemb >= INT_MAX / size)
  151.         return AVERROR(ENOMEM);
  152.     if (!nmemb) {
                ^
  153.         av_freep(ptr);
  154.         return 0;

libavutil/mem.c:153:9: 
  151.         return AVERROR(ENOMEM);
  152.     if (!nmemb) {
  153.         av_freep(ptr);
               ^
  154.         return 0;
  155.     }

libavutil/mem.c:177:1: start of procedure av_freep()
    175. }
    176. 
    177. void av_freep(void *arg)
         ^
    178. {
    179.     void **ptr = (void **)arg;

libavutil/mem.c:179:5: 
    177. void av_freep(void *arg)
    178. {
    179.     void **ptr = (void **)arg;
             ^
    180.     av_free(*ptr);
    181.     *ptr = NULL;

libavutil/mem.c:180:5: 
    178. {
    179.     void **ptr = (void **)arg;
    180.     av_free(*ptr);
             ^
    181.     *ptr = NULL;
    182. }

libavutil/mem.c:165:1: start of procedure av_free()
      163. }
      164. 
      165. void av_free(void *ptr)
           ^
      166. {
      167. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:173:5: 
      171.     _aligned_free(ptr);
      172. #else
      173.     free(ptr);
               ^
      174. #endif
      175. }

libavutil/mem.c:175:1: return from a call to av_free
      173.     free(ptr);
      174. #endif
      175. }
           ^
      176. 
      177. void av_freep(void *arg)

libavutil/mem.c:181:5: 
    179.     void **ptr = (void **)arg;
    180.     av_free(*ptr);
    181.     *ptr = NULL;
             ^
    182. }
    183. 

libavutil/mem.c:182:1: return from a call to av_freep
    180.     av_free(*ptr);
    181.     *ptr = NULL;
    182. }
         ^
    183. 
    184. void *av_mallocz(size_t size)

libavutil/mem.c:154:9: 
  152.     if (!nmemb) {
  153.         av_freep(ptr);
  154.         return 0;
               ^
  155.     }
  156.     ret = av_realloc(*ptrptr, nmemb * size);

libavutil/mem.c:163:1: return from a call to av_reallocp_array
  161.     *ptrptr = ret;
  162.     return 0;
  163. }
       ^
  164. 
  165. void av_free(void *ptr)

libavformat/matroskaenc.c:304:9: Taking false branch
302.         return -1;
303. 
304.     if ((err = av_reallocp_array(&entries, seekhead->num_entries + 1,
             ^
305.                                  sizeof(*entries))) < 0) {
306.         seekhead->num_entries = 0;

libavformat/matroskaenc.c:310:5: 
308.     }
309. 
310.     entries[seekhead->num_entries  ].elementid = elementid;
         ^
311.     entries[seekhead->num_entries++].segmentpos = filepos - seekhead->segment_offset;
312. 

static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid, uint64_t filepos)
{
    mkv_seekhead_entry *entries = seekhead->entries;
    int err;
    if (seekhead->max_entries > 0 && seekhead->max_entries <= seekhead->num_entries)
        return -1;
    if ((err = av_reallocp_array(&entries, seekhead->num_entries + 1,
                                 sizeof(*entries))) < 0) {
        seekhead->num_entries = 0;
        return err;
    }
    entries[seekhead->num_entries  ].elementid = elementid;
    entries[seekhead->num_entries++].segmentpos = filepos - seekhead->segment_offset;
    seekhead->entries = entries;
    return 0;
}
['static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid, uint64_t filepos)\n{\n    mkv_seekhead_entry *entries = seekhead->entries;\n    int err;\n    if (seekhead->max_entries > 0 && seekhead->max_entries <= seekhead->num_entries)\n        return -1;\n    if ((err = av_reallocp_array(&entries, seekhead->num_entries + 1,\n                                 sizeof(*entries))) < 0) {\n        seekhead->num_entries = 0;\n        return err;\n    }\n    entries[seekhead->num_entries  ].elementid = elementid;\n    entries[seekhead->num_entries++].segmentpos = filepos - seekhead->segment_offset;\n    seekhead->entries = entries;\n    return 0;\n}', 'int av_reallocp_array(void *ptr, size_t nmemb, size_t size)\n{\n    void **ptrptr = ptr;\n    void *ret;\n    if (!size || nmemb >= INT_MAX / size)\n        return AVERROR(ENOMEM);\n    if (!nmemb) {\n        av_freep(ptr);\n        return 0;\n    }\n    ret = av_realloc(*ptrptr, nmemb * size);\n    if (!ret) {\n        av_freep(ptr);\n        return AVERROR(ENOMEM);\n    }\n    *ptrptr = ret;\n    return 0;\n}', 'void av_freep(void *arg)\n{\n    void **ptr = (void **)arg;\n    av_free(*ptr);\n    *ptr = NULL;\n}', 'void av_free(void *ptr)\n{\n#if CONFIG_MEMALIGN_HACK\n    if (ptr)\n        free((char *)ptr - ((char *)ptr)[-1]);\n#elif HAVE_ALIGNED_MALLOC\n    _aligned_free(ptr);\n#else\n    free(ptr);\n#endif\n}']