Browse code

wtvdec: prevent memory leak in get_tag()

Peter Ross authored on 2013/01/07 23:48:13
Showing 1 changed files
... ...
@@ -448,15 +448,20 @@ done:
448 448
 
449 449
 static void get_tag(AVFormatContext *s, AVIOContext *pb, const char *key, int type, int length)
450 450
 {
451
-    int buf_size = FFMAX(2*length, LEN_PRETTY_GUID) + 1;
452
-    char *buf = av_malloc(buf_size);
453
-    if (!buf)
454
-        return;
451
+    int buf_size;
452
+    char *buf;
455 453
 
456 454
     if (!strcmp(key, "WM/MediaThumbType")) {
457 455
         avio_skip(pb, length);
458 456
         return;
459
-    } else if (type == 0 && length == 4) {
457
+    }
458
+
459
+    buf_size = FFMAX(2*length, LEN_PRETTY_GUID) + 1;
460
+    buf = av_malloc(buf_size);
461
+    if (!buf)
462
+        return;
463
+
464
+    if (type == 0 && length == 4) {
460 465
         snprintf(buf, buf_size, "%"PRIi32, avio_rl32(pb));
461 466
     } else if (type == 1) {
462 467
         avio_get_str16le(pb, length, buf, buf_size);