diff --git a/ncdump/tst_ncgen4.sh b/ncdump/tst_ncgen4.sh
index a5be263e7..06e481a36 100755
--- a/ncdump/tst_ncgen4.sh
+++ b/ncdump/tst_ncgen4.sh
@@ -1,11 +1,11 @@
-#!/bin/sh
+#!/bin/bash
 # Tests for ncgen4 using list of test cdl files from the cdl4
 # directory, and comparing output to expected results in the expected4
 # directory. Note that these tests are run for classic files in
 # tst_ncgen4_classic.sh
 # Dennis Heimbigner
 
-if test "x$srcdir" = x ; then srcdir=`pwd`; fi 
+if test "x$srcdir" = x ; then srcdir=`pwd`; fi
 . ../test_common.sh
 
 set -e
@@ -17,22 +17,21 @@ set -e
 # 3. Modify the file tst_ncgen_shared.sh to add
 #    the test to the end of the TESTS4 variable
 # 4. Add the new files into cdl4/Makefile.am
-#    and expected4/Makefile.am 
+#    and expected4/Makefile.am
 
 verbose=1
 export verbose
 
 KFLAG=3 ; export KFLAG
 echo "*** Performing diff tests: k=3"
-sh  ${srcdir}/tst_ncgen4_diff.sh
+bash  ${srcdir}/tst_ncgen4_diff.sh
 echo "*** Performing cycle tests: k=3"
-sh  ${srcdir}/tst_ncgen4_cycle.sh
+bash  ${srcdir}/tst_ncgen4_cycle.sh
 KFLAG=4 ; export KFLAG
 echo "*** Performing diff tests: k=4"
-sh  ${srcdir}/tst_ncgen4_diff.sh
+bash  ${srcdir}/tst_ncgen4_diff.sh
 echo "*** Performing cycle tests: k=4"
-sh  ${srcdir}/tst_ncgen4_cycle.sh
+bash  ${srcdir}/tst_ncgen4_cycle.sh
 rm -rf ${RESULTSDIR}
 echo "SUCCESS!!"
 exit 0
-
diff --git a/ncgen/main.c b/ncgen/main.c
index 18ed86163..45c1336bd 100644
--- a/ncgen/main.c
+++ b/ncgen/main.c
@@ -60,6 +60,7 @@ extern FILE *ncgin;
 /* Forward */
 static char* ubasename(char*);
 void usage( void );
+
 int main( int argc, char** argv );
 
 /* Define tables vs modes for legal -k values*/
@@ -157,6 +158,19 @@ static char* LE16 = "\xFF\xFE";       /* UTF-16; little-endian */
 #define DFALTBINNCITERBUFFERSIZE  0x40000 /* about 250k bytes */
 #define DFALTLANGNCITERBUFFERSIZE  0x4000 /* about 15k bytes */
 
+void *emalloc (size_t size) {                  /* check return from malloc */
+  void   *p;
+
+  if (size == 0)
+    return 0;
+  p = (void *) malloc (size);
+  if (p == 0) {
+    exit(NC_ENOMEM);
+  }
+  return p;
+}
+
+
 /* strip off leading path */
 /* result is malloc'd */
 
@@ -296,13 +310,16 @@ main(
               derror("%s: output language is null", progname);
               return(1);
             }
-            lang_name = estrdup(optarg);
-	    for(langs=legallanguages;langs->name != NULL;langs++) {
+            //lang_name = estrdup(optarg);
+            lang_name = (char*) emalloc(strlen(optarg)+1);
+            (void)strcpy(lang_name, optarg);
+
+            for(langs=legallanguages;langs->name != NULL;langs++) {
               if(strcmp(lang_name,langs->name)==0) {
-	  	l_flag = langs->flag;
+                l_flag = langs->flag;
                 break;
               }
-	    }
+            }
 	    if(langs->name == NULL) {
               derror("%s: output language %s not implemented",progname, lang_name);
               nullfree(lang_name);