parfait fixes - kstat, libjniutil
authordevjani.ray@oracle.com <devjani.ray@oracle.com>
Tue, 15 May 2012 15:37:20 -0400
changeset 858 97083523b759
parent 857 0975aadb56a3
child 859 12c80e43cedc
parfait fixes - kstat, libjniutil
usr/src/cmd/rad/mod/kstat/mod_kstat.c
usr/src/lib/libjniutil/libjniutil.c
--- a/usr/src/cmd/rad/mod/kstat/mod_kstat.c	Tue May 15 15:28:14 2012 -0400
+++ b/usr/src/cmd/rad/mod/kstat/mod_kstat.c	Tue May 15 15:37:20 2012 -0400
@@ -234,21 +234,22 @@
 		return (ce_ok);
 	}
 
+	if (kstat_read(kc, ks, NULL) == -1) {
+		rad_mutex_exit(&kstat_lock);
+		return (ce_notfound);
+	}
+
 	kstat_inst_t *kid = malloc(sizeof (kstat_inst_t));
 	if (kid == NULL) {
 		rad_mutex_exit(&kstat_lock);
 		return (ce_nomem);
 	}
 
-	if (kstat_read(kc, ks, NULL) == -1) {
-		rad_mutex_exit(&kstat_lock);
-		return (ce_notfound);
-	}
-
 	rad_instance_t *i = instance_create(adr_name_hold(aname),
 	    &interface_Kstat_svr, kid, (void(*)(void *))kstat_inst_free);
 	if (i == NULL) {
 		rad_mutex_exit(&kstat_lock);
+		free(kid);
 		return (ce_nomem);
 	}
 
--- a/usr/src/lib/libjniutil/libjniutil.c	Tue May 15 15:28:14 2012 -0400
+++ b/usr/src/lib/libjniutil/libjniutil.c	Tue May 15 15:37:20 2012 -0400
@@ -302,7 +302,7 @@
 	const char *str;
 	jsize i;
 
-	result = malloc(len * sizeof (char *));
+	result = calloc(len, sizeof (char *));
 	if (result == NULL) {
 		oomerror(env, "malloc failed");
 		return (NULL);
@@ -335,6 +335,7 @@
 error:
 	for (; i > 0; i--)
 		free(result[i - 1]);
+	free(result);
 	return (NULL);
 }