Merge pie-platform-release to aosp-master - DO NOT MERGE

Change-Id: Ifa7fcb0c9f5a0845612a4fea74a641ac8e75cb64
diff --git a/dexdump/DexDump.cpp b/dexdump/DexDump.cpp
index 4971c21..9b1ac3a 100644
--- a/dexdump/DexDump.cpp
+++ b/dexdump/DexDump.cpp
@@ -128,8 +128,7 @@
 /*
  * Converts a type descriptor to human-readable "dotted" form.  For
  * example, "Ljava/lang/String;" becomes "java.lang.String", and
- * "[I" becomes "int[]".  Also converts '$' to '.', which means this
- * form can't be converted back to a descriptor.
+ * "[I" becomes "int[]".
  */
 static char* descriptorToDot(const char* str)
 {
@@ -166,7 +165,7 @@
     int i;
     for (i = 0; i < targetLen; i++) {
         char ch = str[offset + i];
-        newStr[i] = (ch == '/' || ch == '$') ? '.' : ch;
+        newStr[i] = (ch == '/') ? '.' : ch;
     }
 
     /* add the appropriate number of brackets for arrays */
@@ -181,16 +180,14 @@
 }
 
 /*
- * Converts the class name portion of a type descriptor to human-readable
- * "dotted" form.
+ * Retrieves the class name portion of a type descriptor.
  *
  * Returns a newly-allocated string.
  */
-static char* descriptorClassToDot(const char* str)
+static char* descriptorClassToName(const char* str)
 {
     const char* lastSlash;
     char* newStr;
-    char* cp;
 
     /* reduce to just the class name, trimming trailing ';' */
     lastSlash = strrchr(str, '/');
@@ -201,10 +198,6 @@
 
     newStr = strdup(lastSlash);
     newStr[strlen(lastSlash)-1] = '\0';
-    for (cp = newStr; *cp != '\0'; cp++) {
-        if (*cp == '$')
-            *cp = '.';
-    }
 
     return newStr;
 }
@@ -1325,7 +1318,7 @@
         if (constructor) {
             char* tmp;
 
-            tmp = descriptorClassToDot(backDescriptor);
+            tmp = descriptorClassToName(backDescriptor);
             printf("<constructor name=\"%s\"\n", tmp);
             free(tmp);
 
@@ -1590,7 +1583,7 @@
     } else {
         char* tmp;
 
-        tmp = descriptorClassToDot(classDescriptor);
+        tmp = descriptorClassToName(classDescriptor);
         printf("<class name=\"%s\"\n", tmp);
         free(tmp);
 
diff --git a/dx/Android.mk b/dx/Android.mk
index c0e10a1..bf6acc2 100644
--- a/dx/Android.mk
+++ b/dx/Android.mk
@@ -61,7 +61,7 @@
 
 $(LOCAL_BUILT_MODULE): PRIVATE_PROGUARD_FLAGS:= \
   -include $(addprefix $(LOCAL_PATH)/, shrinkedAndroid.proguard.flags)
-$(LOCAL_BUILT_MODULE): $(call java-lib-files,sdk_v20) \
+$(LOCAL_BUILT_MODULE): $(call java-lib-files,$(call resolve-prebuilt-sdk-module,20)) \
                        $(addprefix $(LOCAL_PATH)/, shrinkedAndroid.proguard.flags)| $(PROGUARD)
 	@echo Proguard: $@
 	$(hide) $(PROGUARD) -injars "$<(**/*.class)" -outjars $@ $(PRIVATE_PROGUARD_FLAGS)
@@ -92,24 +92,6 @@
 
 endif # No TARGET_BUILD_APPS or TARGET_BUILD_PDK
 
-# the dexmerger script
-# ============================================================
-include $(CLEAR_VARS)
-LOCAL_IS_HOST_MODULE := true
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE := dexmerger
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-$(LOCAL_BUILT_MODULE): $(HOST_OUT_JAVA_LIBRARIES)/dx$(COMMON_JAVA_PACKAGE_SUFFIX)
-$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/etc/dexmerger | $(ACP)
-	@echo "Copy: $(PRIVATE_MODULE) ($@)"
-	$(copy-file-to-new-target)
-	$(hide) chmod 755 $@
-
-INTERNAL_DALVIK_MODULES += $(LOCAL_INSTALLED_MODULE)
-
 # the jasmin script
 # ============================================================
 include $(CLEAR_VARS)
@@ -149,7 +131,6 @@
 # ============================================================
 subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
 		junit-tests \
-		src \
 	))
 
 include $(subdirs)
diff --git a/dx/etc/dexmerger b/dx/etc/dexmerger
deleted file mode 100644
index 58fd9ab..0000000
--- a/dx/etc/dexmerger
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Set up prog to be the path of this script, including following symlinks,
-# and set up progdir to be the fully-qualified pathname of its directory.
-prog="$0"
-while [ -h "${prog}" ]; do
-    newProg=`/bin/ls -ld "${prog}"`
-    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
-    if expr "x${newProg}" : 'x/' >/dev/null; then
-        prog="${newProg}"
-    else
-        progdir=`dirname "${prog}"`
-        prog="${progdir}/${newProg}"
-    fi
-done
-oldwd=`pwd`
-progdir=`dirname "${prog}"`
-cd "${progdir}"
-progdir=`pwd`
-prog="${progdir}"/`basename "${prog}"`
-cd "${oldwd}"
-
-jarfile=dx.jar
-libdir="$progdir"
-
-if [ ! -r "$libdir/$jarfile" ]; then
-    # set dx.jar location for the SDK case
-    libdir=`dirname "$progdir"`/platform-tools/lib
-fi
-
-
-if [ ! -r "$libdir/$jarfile" ]; then
-    # set dx.jar location for the Android tree case
-    libdir=`dirname "$progdir"`/framework
-fi
-
-if [ ! -r "$libdir/$jarfile" ]; then
-    echo `basename "$prog"`": can't find $jarfile"
-    exit 1
-fi
-
-# By default, give dexmerger a max heap size of 1 gig. This can be overridden
-# by using a "-J" option (see below).
-defaultMx="-Xmx1024M"
-
-# The following will extract any initial parameters of the form
-# "-J<stuff>" from the command line and pass them to the Java
-# invocation (instead of to dexmerger). This makes it possible for you to add
-# a command-line parameter such as "-JXmx256M" in your scripts, for
-# example. "java" (with no args) and "java -X" give a summary of
-# available options.
-
-javaOpts=""
-
-while expr "x$1" : 'x-J' >/dev/null; do
-    opt=`expr "x$1" : 'x-J\(.*\)'`
-    javaOpts="${javaOpts} -${opt}"
-    if expr "x${opt}" : "xXmx[0-9]" >/dev/null; then
-        defaultMx="no"
-    fi
-    shift
-done
-
-if [ "${defaultMx}" != "no" ]; then
-    javaOpts="${javaOpts} ${defaultMx}"
-fi
-
-if [ "$OSTYPE" = "cygwin" ]; then
-    # For Cygwin, convert the jarfile path into native Windows style.
-    jarpath=`cygpath -w "$libdir/$jarfile"`
-else
-    jarpath="$libdir/$jarfile"
-fi
-
-exec java $javaOpts -cp "$jarpath" com.android.dx.merge.DexMerger "$@"
diff --git a/dx/src/Android.bp b/dx/src/Android.bp
new file mode 100644
index 0000000..9459e27
--- /dev/null
+++ b/dx/src/Android.bp
@@ -0,0 +1,47 @@
+// Copyright (C) 2006 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+droidstubs_host {
+    name: "dx-doc-stubs",
+    srcs: [
+        "com/**/*.java",
+    ],
+    args: "--hidden",
+    create_doc_stubs: true,
+    product_variables: {
+        pdk: {
+            enabled: false,
+        },
+        unbundled_build: {
+            enabled: false,
+        },
+    },
+}
+
+droiddoc_host {
+    name: "dx-docs",
+    srcs: [
+        ":dx-doc-stubs",
+    ],
+    custom_template: "droiddoc-templates-sdk",
+    create_stubs: false,
+    product_variables: {
+        pdk: {
+            enabled: false,
+        },
+        unbundled_build: {
+            enabled: false,
+        },
+    },
+}
diff --git a/dx/src/Android.mk b/dx/src/Android.mk
deleted file mode 100644
index 9bded44..0000000
--- a/dx/src/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright 2006 The Android Open Source Project
-#
-LOCAL_PATH := $(call my-dir)
-
-# This tool is prebuilt if we're doing an app-only build.
-ifeq ($(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK)),)
-
-dx_src_files := $(call all-subdir-java-files)
-
-# the documentation
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(dx_src_files) $(call all-subdir-html-files)
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE:= dx
-LOCAL_DROIDDOC_OPTIONS := -hidden
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_IS_HOST_MODULE := true
-
-include $(BUILD_DROIDDOC)
-
-dx_src_files :=
-
-endif # No TARGET_BUILD_APPS or TARGET_BUILD_PDK
diff --git a/dx/src/com/android/dx/dex/file/MethodHandlesSection.java b/dx/src/com/android/dx/dex/file/MethodHandlesSection.java
index f293d05..5aca47e 100644
--- a/dx/src/com/android/dx/dex/file/MethodHandlesSection.java
+++ b/dx/src/com/android/dx/dex/file/MethodHandlesSection.java
@@ -55,7 +55,7 @@
         return methodHandles.values();
     }
 
-    public void intern(CstMethodHandle methodHandle) {
+    public synchronized void intern(CstMethodHandle methodHandle) {
         if (methodHandle == null) {
             throw new NullPointerException("methodHandle == null");
         }
diff --git a/dx/tests/run-test b/dx/tests/run-test
index f205c46..a781d8d 100755
--- a/dx/tests/run-test
+++ b/dx/tests/run-test
@@ -54,6 +54,7 @@
 expected="expected.txt"
 output="out.txt"
 
+clean_on_exit="yes"
 dev_mode="no"
 update_mode="no"
 tmpdir=/tmp/test-$$
@@ -61,7 +62,8 @@
 
 while [[ "x$1" = "x-"* ]]; do
     case $1 in
-         --dev) dev_mode="yes" ;;
+        --dev) dev_mode="yes" ;;
+        --no-clean) clean_on_exit="no" ;;
          --output_dir)
              tmpdir=$2
              shift ;;
@@ -156,7 +158,11 @@
 
 if [ "$good" = "yes" ]; then
     cd "$oldwd"
-    rm -rf "$tmpdir"
+    if [ "$clean_on_exit" = "yes" ]; then
+        rm -rf "$tmpdir"
+    else
+        echo "Test artifacts left in $tmpdir"
+    fi
     exit 0
 fi
 
diff --git a/libdex/Android.bp b/libdex/Android.bp
index 63600c6..ad0128b 100644
--- a/libdex/Android.bp
+++ b/libdex/Android.bp
@@ -38,7 +38,6 @@
     include_dirs: [
         "dalvik",
         "external/zlib",
-        "external/safe-iop/include",
     ],
     static_libs: ["liblog"],
     whole_static_libs: ["libziparchive"],
@@ -46,6 +45,7 @@
     cflags: [
         "-Wall",
         "-Werror",
+        "-Wimplicit-fallthrough",
     ],
     target: {
         android: {
diff --git a/libdex/DexDataMap.cpp b/libdex/DexDataMap.cpp
index 65da14c..18e4a45 100644
--- a/libdex/DexDataMap.cpp
+++ b/libdex/DexDataMap.cpp
@@ -19,7 +19,6 @@
  */
 
 #include "DexDataMap.h"
-#include <safe_iop.h>
 #include <stdlib.h>
 
 /*
@@ -27,18 +26,15 @@
  */
 DexDataMap* dexDataMapAlloc(u4 maxCount) {
     /*
-     * Allocate a single chunk for the DexDataMap per se as well as the
+     * Allocate a single chunk for the DexDataMap itself as well as the
      * two arrays.
      */
     size_t size = 0;
     DexDataMap* map = NULL;
 
-    /*
-     * Avoiding pulling in safe_iop for safe_iopf.
-     */
     const u4 sizeOfItems = (u4) (sizeof(u4) + sizeof(u2));
-    if (!safe_mul(&size, maxCount, sizeOfItems) ||
-        !safe_add(&size, size, sizeof(DexDataMap))) {
+    if (__builtin_mul_overflow(maxCount, sizeOfItems, &size) ||
+        __builtin_add_overflow(size, sizeof(DexDataMap), &size)) {
       return NULL;
     }
 
diff --git a/libdex/DexFile.h b/libdex/DexFile.h
index a12f025..7fc7d05 100644
--- a/libdex/DexFile.h
+++ b/libdex/DexFile.h
@@ -33,15 +33,21 @@
 #ifndef LIBDEX_DEXFILE_H_
 #define LIBDEX_DEXFILE_H_
 
+/*
+ * Annotation to tell clang that we intend to fall through from one case to
+ * another in a switch. Sourced from android-base/macros.h.
+ */
+#define FALLTHROUGH_INTENDED [[clang::fallthrough]]
+
 #ifndef LOG_TAG
 # define LOG_TAG "libdex"
 #endif
+#include <log/log.h>
 
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <assert.h>
-#include "cutils/log.h"
 
 /*
  * If "very verbose" logging is enabled, make it equivalent to ALOGV.
diff --git a/libdex/DexOpcodes.h b/libdex/DexOpcodes.h
index 1c684ab..f4dcd6b 100644
--- a/libdex/DexOpcodes.h
+++ b/libdex/DexOpcodes.h
@@ -609,11 +609,7 @@
      * that data tables get generated in a consistent way.
      */
     int lowByte = codeUnit & 0xff;
-    if (lowByte != 0xff) {
-        return (Opcode) lowByte;
-    } else {
-        return (Opcode) ((codeUnit >> 8) | 0x100);
-    }
+    return (Opcode) lowByte;
 }
 
 /*
diff --git a/libdex/DexSwapVerify.cpp b/libdex/DexSwapVerify.cpp
index 8836ab2..8ffc743 100644
--- a/libdex/DexSwapVerify.cpp
+++ b/libdex/DexSwapVerify.cpp
@@ -25,7 +25,6 @@
 #include "DexUtf.h"
 #include "Leb128.h"
 
-#include <safe_iop.h>
 #include <zlib.h>
 
 #include <stdlib.h>
@@ -140,7 +139,8 @@
 #define CHECK_LIST_SIZE(_ptr, _count, _elemSize) {                          \
         const u1* _start = (const u1*) (_ptr);                              \
         const u1* _end = _start + ((_count) * (_elemSize));                 \
-        if (!safe_mul(nullptr, (_count), (_elemSize)) ||                    \
+        u4 _dummy;                                                          \
+        if (__builtin_mul_overflow((_count), (_elemSize), &_dummy) ||       \
             !checkPtrRange(state, _start, _end, #_ptr)) {                   \
             return 0;                                                       \
         }                                                                   \
@@ -617,7 +617,7 @@
                 ALOGE("Invalid use of void");
                 return false;
             }
-            // Fall through.
+            FALLTHROUGH_INTENDED;
         }
         case 'B':
         case 'C':
@@ -2908,7 +2908,8 @@
     if ((memcmp(version, DEX_MAGIC_VERS, 4) != 0) &&
         (memcmp(version, DEX_MAGIC_VERS_API_13, 4) != 0) &&
         (memcmp(version, DEX_MAGIC_VERS_37, 4) != 0) &&
-        (memcmp(version, DEX_MAGIC_VERS_38, 4) != 0)) {
+        (memcmp(version, DEX_MAGIC_VERS_38, 4) != 0) &&
+        (memcmp(version, DEX_MAGIC_VERS_39, 4) != 0)) {
         /*
          * Magic was correct, but this is an unsupported older or
          * newer format variant.
diff --git a/libdex/InstrUtils.cpp b/libdex/InstrUtils.cpp
index 9039f59..56f5dd8 100644
--- a/libdex/InstrUtils.cpp
+++ b/libdex/InstrUtils.cpp
@@ -619,10 +619,11 @@
                  * instruction, but it's labeled G in the spec.
                  */
                 pDec->arg[4] = INST_A(inst);
+                FALLTHROUGH_INTENDED;
             }
-            case 4: pDec->arg[3] = (regList >> 12) & 0x0f;
-            case 3: pDec->arg[2] = (regList >> 8) & 0x0f;
-            case 2: pDec->arg[1] = (regList >> 4) & 0x0f;
+            case 4: pDec->arg[3] = (regList >> 12) & 0x0f; FALLTHROUGH_INTENDED;
+            case 3: pDec->arg[2] = (regList >> 8) & 0x0f; FALLTHROUGH_INTENDED;
+            case 2: pDec->arg[1] = (regList >> 4) & 0x0f; FALLTHROUGH_INTENDED;
             case 1: pDec->vC = pDec->arg[0] = regList & 0x0f; break;
             case 0: break; // Valid, but no need to do anything.
             default:
diff --git a/tools/dexdeps/Android.bp b/tools/dexdeps/Android.bp
new file mode 100644
index 0000000..98b3aba
--- /dev/null
+++ b/tools/dexdeps/Android.bp
@@ -0,0 +1,22 @@
+// Copyright (C) 2009 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+java_binary_host {
+    name: "dexdeps",
+    manifest: "etc/manifest.txt",
+    srcs: [
+        "src/**/*.java",
+    ],
+    wrapper: "etc/dexdeps",
+}
diff --git a/tools/dexdeps/Android.mk b/tools/dexdeps/Android.mk
deleted file mode 100644
index e1b7e73..0000000
--- a/tools/dexdeps/Android.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (C) 2009 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-# We use copy-file-to-new-target so that the installed
-# script files' timestamps are at least as new as the
-# .jar files they wrap.
-
-# the dexdeps script
-# ============================================================
-include $(CLEAR_VARS)
-LOCAL_IS_HOST_MODULE := true
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := EXECUTABLES
-LOCAL_MODULE := dexdeps
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-$(LOCAL_BUILT_MODULE): $(HOST_OUT_JAVA_LIBRARIES)/dexdeps$(COMMON_JAVA_PACKAGE_SUFFIX)
-$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/etc/dexdeps | $(ACP)
-	@echo "Copy: $(PRIVATE_MODULE) ($@)"
-	$(copy-file-to-new-target)
-	$(hide) chmod 755 $@
-
-INTERNAL_DALVIK_MODULES += $(LOCAL_INSTALLED_MODULE)
-
-# the other stuff
-# ============================================================
-subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
-		src \
-	))
-
-include $(subdirs)
diff --git a/tools/dexdeps/src/Android.bp b/tools/dexdeps/src/Android.bp
new file mode 100644
index 0000000..ad76e4d
--- /dev/null
+++ b/tools/dexdeps/src/Android.bp
@@ -0,0 +1,30 @@
+// Copyright (C) 2009 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+droidstubs {
+    name: "dexdeps-doc-stubs",
+    srcs: [
+        "com/**/*.java",
+    ],
+    create_doc_stubs: true,
+}
+
+droiddoc {
+    name: "dexdeps-docs",
+    srcs: [
+        ":dexdeps-doc-stubs",
+    ],
+    custom_template: "droiddoc-templates-sdk",
+    create_stubs: false,
+}
diff --git a/tools/dexdeps/src/Android.mk b/tools/dexdeps/src/Android.mk
deleted file mode 100644
index 8e4abaf..0000000
--- a/tools/dexdeps/src/Android.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright (C) 2009 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-
-# dexdeps java library
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-LOCAL_JAR_MANIFEST := ../etc/manifest.txt
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE:= dexdeps
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-INTERNAL_DALVIK_MODULES += $(LOCAL_INSTALLED_MODULE)
-
-include $(BUILD_DROIDDOC)
diff --git a/tools/hprof-conv/HprofConv.c b/tools/hprof-conv/HprofConv.c
index a69440c..cc90176 100644
--- a/tools/hprof-conv/HprofConv.c
+++ b/tools/hprof-conv/HprofConv.c
@@ -764,9 +764,9 @@
     res = 2;
 
 finish:
-    if (in != stdin)
+    if (in != stdin && in != NULL)
         fclose(in);
-    if (out != stdout)
+    if (out != stdout && out != NULL)
         fclose(out);
     return res;
 }