svc_encoder_rtc.c: Fix an invalid read and leaks

Null-terminate the copy of the `input` string to prevent strtok() from
overreading.

Destroy the decoder to avoid memory leaks.

Bug: aomedia:3404
Change-Id: Ic27d9df4c6346e2d89b1a000de961971e35569cd
diff --git a/examples/svc_encoder_rtc.c b/examples/svc_encoder_rtc.c
index 9177363..b6408dc 100644
--- a/examples/svc_encoder_rtc.c
+++ b/examples/svc_encoder_rtc.c
@@ -252,9 +252,9 @@
       (option1 == NULL && type == SCALE_FACTOR))
     return AOM_CODEC_INVALID_PARAM;
 
-  input_string = malloc(strlen(input));
+  input_string = malloc(strlen(input) + 1);
   if (!input_string) die("Failed to allocate input string.");
-  memcpy(input_string, input, strlen(input));
+  memcpy(input_string, input, strlen(input) + 1);
   if (input_string == NULL) return AOM_CODEC_MEM_ERROR;
   token = strtok(input_string, delim);  // NOLINT
   for (i = 0; i < num_layers; ++i) {
@@ -1695,6 +1695,13 @@
 
   if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
 
+#if CONFIG_AV1_DECODER
+  if (app_input.decode) {
+    if (aom_codec_destroy(&decoder))
+      die_codec(&decoder, "Failed to destroy decoder");
+  }
+#endif
+
 #if CONFIG_INTERNAL_STATS
   fprintf(stats_file, "No mismatch detected in recon buffers\n");
   fclose(stats_file);