libavformat/hls.c:496: error: Memory Leak
  memory dynamically allocated to `buf` by call to `av_opt_get()` at line 486, column 13 is not reachable after line 496, column 1.

libavformat/hls.c:477:1: start of procedure save_avio_options()
475. }
476. 
477. static int save_avio_options(AVFormatContext *s)
     ^
478. {
479.     HLSContext *c = s->priv_data;

libavformat/hls.c:479:5: 
477. static int save_avio_options(AVFormatContext *s)
478. {
479.     HLSContext *c = s->priv_data;
         ^
480.     static const char * const opts[] = { "headers", "user_agent", NULL };
481.     const char * const *opt = opts;

libavformat/hls.c:480:5: 
478. {
479.     HLSContext *c = s->priv_data;
480.     static const char * const opts[] = { "headers", "user_agent", NULL };
         ^
481.     const char * const *opt = opts;
482.     uint8_t *buf;

libavformat/hls.c:481:5: 
479.     HLSContext *c = s->priv_data;
480.     static const char * const opts[] = { "headers", "user_agent", NULL };
481.     const char * const *opt = opts;
         ^
482.     uint8_t *buf;
483.     int ret = 0;

libavformat/hls.c:483:5: 
481.     const char * const *opt = opts;
482.     uint8_t *buf;
483.     int ret = 0;
         ^
484. 
485.     while (*opt) {

libavformat/hls.c:485:12: Loop condition is true. Entering loop body
483.     int ret = 0;
484. 
485.     while (*opt) {
                ^
486.         if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
487.             ret = av_dict_set(&c->avio_opts, *opt, buf,

libavformat/hls.c:486:13: 
484. 
485.     while (*opt) {
486.         if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
                 ^
487.             ret = av_dict_set(&c->avio_opts, *opt, buf,
488.                               AV_DICT_DONT_STRDUP_VAL);

libavutil/opt.c:368:1: start of procedure av_opt_get()
  366. }
  367. 
  368. int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
       ^
  369. {
  370.     void *dst, *target_obj;

libavutil/opt.c:371:5: Skipping av_opt_find2(): empty list of specs
  369. {
  370.     void *dst, *target_obj;
  371.     const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
           ^
  372.     uint8_t *bin, buf[128];
  373.     int len, i, ret;

libavutil/opt.c:375:10: Taking false branch
  373.     int len, i, ret;
  374. 
  375.     if (!o || !target_obj)
                ^
  376.         return AVERROR_OPTION_NOT_FOUND;
  377. 

libavutil/opt.c:375:16: Taking false branch
  373.     int len, i, ret;
  374. 
  375.     if (!o || !target_obj)
                      ^
  376.         return AVERROR_OPTION_NOT_FOUND;
  377. 

libavutil/opt.c:378:5: 
  376.         return AVERROR_OPTION_NOT_FOUND;
  377. 
  378.     dst = (uint8_t *)target_obj + o->offset;
           ^
  379. 
  380.     buf[0] = 0;

libavutil/opt.c:380:5: 
  378.     dst = (uint8_t *)target_obj + o->offset;
  379. 
  380.     buf[0] = 0;
           ^
  381.     switch (o->type) {
  382.     case AV_OPT_TYPE_FLAGS:

libavutil/opt.c:381:5: 
  379. 
  380.     buf[0] = 0;
  381.     switch (o->type) {
           ^
  382.     case AV_OPT_TYPE_FLAGS:
  383.         ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);

libavutil/opt.c:382:5: Switch condition is false. Skipping switch case
  380.     buf[0] = 0;
  381.     switch (o->type) {
  382.     case AV_OPT_TYPE_FLAGS:
           ^
  383.         ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
  384.         break;

libavutil/opt.c:385:5: Switch condition is false. Skipping switch case
  383.         ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
  384.         break;
  385.     case AV_OPT_TYPE_INT:
           ^
  386.         ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
  387.         break;

libavutil/opt.c:388:5: Switch condition is false. Skipping switch case
  386.         ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
  387.         break;
  388.     case AV_OPT_TYPE_INT64:
           ^
  389.         ret = snprintf(buf, sizeof(buf), "%" PRId64, *(int64_t *)dst);
  390.         break;

libavutil/opt.c:391:5: Switch condition is false. Skipping switch case
  389.         ret = snprintf(buf, sizeof(buf), "%" PRId64, *(int64_t *)dst);
  390.         break;
  391.     case AV_OPT_TYPE_FLOAT:
           ^
  392.         ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
  393.         break;

libavutil/opt.c:394:5: Switch condition is false. Skipping switch case
  392.         ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
  393.         break;
  394.     case AV_OPT_TYPE_DOUBLE:
           ^
  395.         ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
  396.         break;

libavutil/opt.c:397:5: Switch condition is false. Skipping switch case
  395.         ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
  396.         break;
  397.     case AV_OPT_TYPE_RATIONAL:
           ^
  398.         ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num,
  399.                        ((AVRational *)dst)->den);

libavutil/opt.c:401:5: Switch condition is true. Entering switch case
  399.                        ((AVRational *)dst)->den);
  400.         break;
  401.     case AV_OPT_TYPE_STRING:
           ^
  402.         if (*(uint8_t **)dst)
  403.             *out_val = av_strdup(*(uint8_t **)dst);

libavutil/opt.c:402:13: Taking false branch
  400.         break;
  401.     case AV_OPT_TYPE_STRING:
  402.         if (*(uint8_t **)dst)
                   ^
  403.             *out_val = av_strdup(*(uint8_t **)dst);
  404.         else

libavutil/opt.c:405:13: 
  403.             *out_val = av_strdup(*(uint8_t **)dst);
  404.         else
  405.             *out_val = av_strdup("");
                   ^
  406.         return *out_val ? 0 : AVERROR(ENOMEM);
  407.     case AV_OPT_TYPE_BINARY:

libavutil/mem.c:196:1: start of procedure av_strdup()
    194. }
    195. 
    196. char *av_strdup(const char *s)
         ^
    197. {
    198.     char *ptr = NULL;

libavutil/mem.c:198:5: 
    196. char *av_strdup(const char *s)
    197. {
    198.     char *ptr = NULL;
             ^
    199.     if (s) {
    200.         int len = strlen(s) + 1;

libavutil/mem.c:199:9: Taking true branch
    197. {
    198.     char *ptr = NULL;
    199.     if (s) {
                 ^
    200.         int len = strlen(s) + 1;
    201.         ptr = av_realloc(NULL, len);

libavutil/mem.c:200:9: 
    198.     char *ptr = NULL;
    199.     if (s) {
    200.         int len = strlen(s) + 1;
                 ^
    201.         ptr = av_realloc(NULL, len);
    202.         if (ptr)

libavutil/mem.c:201:9: 
    199.     if (s) {
    200.         int len = strlen(s) + 1;
    201.         ptr = av_realloc(NULL, len);
                 ^
    202.         if (ptr)
    203.             memcpy(ptr, s, len);

libavutil/mem.c:107:1: start of procedure av_realloc()
      105. }
      106. 
      107. void *av_realloc(void *ptr, size_t size)
           ^
      108. {
      109.     /* let's disallow possibly ambiguous cases */

libavutil/mem.c:110:9: Taking false branch
      108. {
      109.     /* let's disallow possibly ambiguous cases */
      110.     if (size > (INT_MAX - 16))
                   ^
      111.         return NULL;
      112. 

libavutil/mem.c:116:5: 
      114.     return _aligned_realloc(ptr, size, 32);
      115. #else
      116.     return realloc(ptr, size);
               ^
      117. #endif
      118. }

libavutil/mem.c:118:1: return from a call to av_realloc
      116.     return realloc(ptr, size);
      117. #endif
      118. }
           ^
      119. 
      120. int av_reallocp(void *ptr, size_t size)

libavutil/mem.c:202:13: Taking true branch
    200.         int len = strlen(s) + 1;
    201.         ptr = av_realloc(NULL, len);
    202.         if (ptr)
                     ^
    203.             memcpy(ptr, s, len);
    204.     }

libavutil/mem.c:203:13: 
    201.         ptr = av_realloc(NULL, len);
    202.         if (ptr)
    203.             memcpy(ptr, s, len);
                     ^
    204.     }
    205.     return ptr;

libavutil/mem.c:205:5: 
    203.             memcpy(ptr, s, len);
    204.     }
    205.     return ptr;
             ^
    206. }
    207. 

libavutil/mem.c:206:1: return from a call to av_strdup
    204.     }
    205.     return ptr;
    206. }
         ^
    207. 
    208. char *av_strndup(const char *s, size_t len)

libavutil/opt.c:406:16: Condition is true
  404.         else
  405.             *out_val = av_strdup("");
  406.         return *out_val ? 0 : AVERROR(ENOMEM);
                      ^
  407.     case AV_OPT_TYPE_BINARY:
  408.         len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));

libavutil/opt.c:406:9: 
  404.         else
  405.             *out_val = av_strdup("");
  406.         return *out_val ? 0 : AVERROR(ENOMEM);
               ^
  407.     case AV_OPT_TYPE_BINARY:
  408.         len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));

libavutil/opt.c:425:1: return from a call to av_opt_get
  423.     *out_val = av_strdup(buf);
  424.     return *out_val ? 0 : AVERROR(ENOMEM);
  425. }
       ^
  426. 
  427. static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum,

libavformat/hls.c:486:13: Taking true branch
484. 
485.     while (*opt) {
486.         if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
                 ^
487.             ret = av_dict_set(&c->avio_opts, *opt, buf,
488.                               AV_DICT_DONT_STRDUP_VAL);

libavformat/hls.c:487:13: 
485.     while (*opt) {
486.         if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
487.             ret = av_dict_set(&c->avio_opts, *opt, buf,
                 ^
488.                               AV_DICT_DONT_STRDUP_VAL);
489.             if (ret < 0)

libavutil/dict.c:68:1: start of procedure av_dict_set()
  66. }
  67. 
  68. int av_dict_set(AVDictionary **pm, const char *key, const char *value,
      ^
  69.                 int flags)
  70. {

libavutil/dict.c:71:5: 
  69.                 int flags)
  70. {
  71.     AVDictionary *m = *pm;
          ^
  72.     AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
  73.     char *oldval = NULL;

libavutil/dict.c:72:5: Skipping av_dict_get(): empty list of specs
  70. {
  71.     AVDictionary *m = *pm;
  72.     AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
          ^
  73.     char *oldval = NULL;
  74.     int allocated = !!m;

libavutil/dict.c:73:5: 
  71.     AVDictionary *m = *pm;
  72.     AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
  73.     char *oldval = NULL;
          ^
  74.     int allocated = !!m;
  75. 

libavutil/dict.c:74:23: Condition is false
  72.     AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
  73.     char *oldval = NULL;
  74.     int allocated = !!m;
                            ^
  75. 
  76.     if (!m)

libavutil/dict.c:74:21: 
  72.     AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
  73.     char *oldval = NULL;
  74.     int allocated = !!m;
                          ^
  75. 
  76.     if (!m)

libavutil/dict.c:74:5: 
  72.     AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
  73.     char *oldval = NULL;
  74.     int allocated = !!m;
          ^
  75. 
  76.     if (!m)

libavutil/dict.c:76:10: Taking false branch
  74.     int allocated = !!m;
  75. 
  76.     if (!m)
               ^
  77.         m = *pm = av_mallocz(sizeof(*m));
  78.     if (!m)

libavutil/dict.c:78:10: Taking false branch
  76.     if (!m)
  77.         m = *pm = av_mallocz(sizeof(*m));
  78.     if (!m)
               ^
  79.         return AVERROR(ENOMEM);
  80. 

libavutil/dict.c:81:9: Taking false branch
  79.         return AVERROR(ENOMEM);
  80. 
  81.     if (tag) {
              ^
  82.         if (flags & AV_DICT_DONT_OVERWRITE) {
  83.             if (flags & AV_DICT_DONT_STRDUP_KEY) av_free(key);

libavutil/dict.c:94:9: 
  92.         *tag = m->elems[--m->count];
  93.     } else {
  94.         int ret = av_reallocp_array(&m->elems,
              ^
  95.                                     m->count + 1, sizeof(*m->elems));
  96.         if (ret < 0) {

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

libavutil/mem.c:152:10: Taking false branch
    150.     void *val;
    151. 
    152.     if (!size || nmemb >= INT_MAX / size)
                  ^
    153.         return AVERROR(ENOMEM);
    154.     if (!nmemb) {

libavutil/mem.c:152:18: Taking true branch
    150.     void *val;
    151. 
    152.     if (!size || nmemb >= INT_MAX / size)
                          ^
    153.         return AVERROR(ENOMEM);
    154.     if (!nmemb) {

libavutil/mem.c:153:9: 
    151. 
    152.     if (!size || nmemb >= INT_MAX / size)
    153.         return AVERROR(ENOMEM);
                 ^
    154.     if (!nmemb) {
    155.         av_freep(ptr);

libavutil/mem.c:168:1: return from a call to av_reallocp_array
    166.     memcpy(ptr, &val, sizeof(val));
    167.     return 0;
    168. }
         ^
    169. 
    170. void av_free(void *ptr)

libavutil/dict.c:96:13: Taking true branch
  94.         int ret = av_reallocp_array(&m->elems,
  95.                                     m->count + 1, sizeof(*m->elems));
  96.         if (ret < 0) {
                  ^
  97.             if (allocated)
  98.                 av_freep(pm);

libavutil/dict.c:97:17: Taking true branch
  95.                                     m->count + 1, sizeof(*m->elems));
  96.         if (ret < 0) {
  97.             if (allocated)
                      ^
  98.                 av_freep(pm);
  99. 

libavutil/dict.c:98:17: Skipping av_freep(): empty list of specs
   96.         if (ret < 0) {
   97.             if (allocated)
   98.                 av_freep(pm);
                       ^
   99. 
  100.             return ret;

libavutil/dict.c:100:13: 
   98.                 av_freep(pm);
   99. 
  100.             return ret;
                   ^
  101.         }
  102.     }

libavutil/dict.c:126:1: return from a call to av_dict_set
  124. 
  125.     return 0;
  126. }
       ^
  127. 
  128. static int parse_key_value_pair(AVDictionary **pm, const char **buf,

libavformat/hls.c:489:17: Taking true branch
487.             ret = av_dict_set(&c->avio_opts, *opt, buf,
488.                               AV_DICT_DONT_STRDUP_VAL);
489.             if (ret < 0)
                     ^
490.                 return ret;
491.         }

libavformat/hls.c:490:17: 
488.                               AV_DICT_DONT_STRDUP_VAL);
489.             if (ret < 0)
490.                 return ret;
                     ^
491.         }
492.         opt++;

libavformat/hls.c:496:1: return from a call to save_avio_options
494. 
495.     return ret;
496. }
     ^
497. 
498. static int nested_io_open(AVFormatContext *s, AVIOContext **pb, const char *url,

static int save_avio_options(AVFormatContext *s)
{
    HLSContext *c = s->priv_data;
    static const char * const opts[] = { "headers", "user_agent", NULL };
    const char * const *opt = opts;
    uint8_t *buf;
    int ret = 0;
    while (*opt) {
        if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {
            ret = av_dict_set(&c->avio_opts, *opt, buf,
                              AV_DICT_DONT_STRDUP_VAL);
            if (ret < 0)
                return ret;
        }
        opt++;
    }
    return ret;
}
['static int save_avio_options(AVFormatContext *s)\n{\n    HLSContext *c = s->priv_data;\n    static const char * const opts[] = { "headers", "user_agent", NULL };\n    const char * const *opt = opts;\n    uint8_t *buf;\n    int ret = 0;\n    while (*opt) {\n        if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {\n            ret = av_dict_set(&c->avio_opts, *opt, buf,\n                              AV_DICT_DONT_STRDUP_VAL);\n            if (ret < 0)\n                return ret;\n        }\n        opt++;\n    }\n    return ret;\n}', 'int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)\n{\n    void *dst, *target_obj;\n    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);\n    uint8_t *bin, buf[128];\n    int len, i, ret;\n    if (!o || !target_obj)\n        return AVERROR_OPTION_NOT_FOUND;\n    dst = (uint8_t *)target_obj + o->offset;\n    buf[0] = 0;\n    switch (o->type) {\n    case AV_OPT_TYPE_FLAGS:\n        ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);\n        break;\n    case AV_OPT_TYPE_INT:\n        ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);\n        break;\n    case AV_OPT_TYPE_INT64:\n        ret = snprintf(buf, sizeof(buf), "%" PRId64, *(int64_t *)dst);\n        break;\n    case AV_OPT_TYPE_FLOAT:\n        ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);\n        break;\n    case AV_OPT_TYPE_DOUBLE:\n        ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);\n        break;\n    case AV_OPT_TYPE_RATIONAL:\n        ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num,\n                       ((AVRational *)dst)->den);\n        break;\n    case AV_OPT_TYPE_STRING:\n        if (*(uint8_t **)dst)\n            *out_val = av_strdup(*(uint8_t **)dst);\n        else\n            *out_val = av_strdup("");\n        return *out_val ? 0 : AVERROR(ENOMEM);\n    case AV_OPT_TYPE_BINARY:\n        len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));\n        if ((uint64_t)len * 2 + 1 > INT_MAX)\n            return AVERROR(EINVAL);\n        if (!(*out_val = av_malloc(len * 2 + 1)))\n            return AVERROR(ENOMEM);\n        bin = *(uint8_t **)dst;\n        for (i = 0; i < len; i++)\n            snprintf(*out_val + i * 2, 3, "%02X", bin[i]);\n        return 0;\n    default:\n        return AVERROR(EINVAL);\n    }\n    if (ret >= sizeof(buf))\n        return AVERROR(EINVAL);\n    *out_val = av_strdup(buf);\n    return *out_val ? 0 : AVERROR(ENOMEM);\n}', 'char *av_strdup(const char *s)\n{\n    char *ptr = NULL;\n    if (s) {\n        int len = strlen(s) + 1;\n        ptr = av_realloc(NULL, len);\n        if (ptr)\n            memcpy(ptr, s, len);\n    }\n    return ptr;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n    if (size > (INT_MAX - 16))\n        return NULL;\n#if HAVE_ALIGNED_MALLOC\n    return _aligned_realloc(ptr, size, 32);\n#else\n    return realloc(ptr, size);\n#endif\n}', 'int av_dict_set(AVDictionary **pm, const char *key, const char *value,\n                int flags)\n{\n    AVDictionary *m = *pm;\n    AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);\n    char *oldval = NULL;\n    int allocated = !!m;\n    if (!m)\n        m = *pm = av_mallocz(sizeof(*m));\n    if (!m)\n        return AVERROR(ENOMEM);\n    if (tag) {\n        if (flags & AV_DICT_DONT_OVERWRITE) {\n            if (flags & AV_DICT_DONT_STRDUP_KEY) av_free(key);\n            if (flags & AV_DICT_DONT_STRDUP_VAL) av_free(value);\n            return 0;\n        }\n        if (flags & AV_DICT_APPEND)\n            oldval = tag->value;\n        else\n            av_free(tag->value);\n        av_free(tag->key);\n        *tag = m->elems[--m->count];\n    } else {\n        int ret = av_reallocp_array(&m->elems,\n                                    m->count + 1, sizeof(*m->elems));\n        if (ret < 0) {\n            if (allocated)\n                av_freep(pm);\n            return ret;\n        }\n    }\n    if (value) {\n        if (flags & AV_DICT_DONT_STRDUP_KEY)\n            m->elems[m->count].key = key;\n        else\n            m->elems[m->count].key = av_strdup(key);\n        if (flags & AV_DICT_DONT_STRDUP_VAL) {\n            m->elems[m->count].value = value;\n        } else if (oldval && flags & AV_DICT_APPEND) {\n            int len = strlen(oldval) + strlen(value) + 1;\n            if (!(oldval = av_realloc(oldval, len)))\n                return AVERROR(ENOMEM);\n            av_strlcat(oldval, value, len);\n            m->elems[m->count].value = oldval;\n        } else\n            m->elems[m->count].value = av_strdup(value);\n        m->count++;\n    }\n    if (!m->count) {\n        av_free(m->elems);\n        av_freep(pm);\n    }\n    return 0;\n}', 'int av_reallocp_array(void *ptr, size_t nmemb, size_t size)\n{\n    void *val;\n    if (!size || nmemb >= INT_MAX / size)\n        return AVERROR(ENOMEM);\n    if (!nmemb) {\n        av_freep(ptr);\n        return 0;\n    }\n    memcpy(&val, ptr, sizeof(val));\n    val = av_realloc(val, nmemb * size);\n    if (!val) {\n        av_freep(ptr);\n        return AVERROR(ENOMEM);\n    }\n    memcpy(ptr, &val, sizeof(val));\n    return 0;\n}']