
This is the second version of this patch file.  The first was missing corrections for some paths that could strand memory.

Patch sent to perfmon2 mailing list 2/9/2015.


### Eclipse Workspace Patch 1.0
#P papi
Index: src/libpfm4/lib/pfmlib_common.c
===================================================================
RCS file: /depot/devenv/bullxde/perftools/papi_repo/papi/src/libpfm4/lib/pfmlib_common.c,v
retrieving revision 1.18
diff -u -r1.18 pfmlib_common.c
--- src/libpfm4/lib/pfmlib_common.c	20 Oct 2014 20:15:50 -0000	1.18
+++ src/libpfm4/lib/pfmlib_common.c	9 Feb 2015 20:05:17 -0000
@@ -812,8 +812,11 @@
 	memset(&e, 0, sizeof(e));
 
 	ret = pfmlib_parse_event(str, &e);
-	if (ret == PFM_SUCCESS)
-		return pfmlib_pidx2idx(e.pmu, e.event);
+	if (ret == PFM_SUCCESS) {
+		// the parse worked, save the libpfm4 index so we can return it and free the pattrs data that was allocated from the heap
+		ret = pfmlib_pidx2idx(e.pmu, e.event);
+		pfmlib_release_event(&e);
+	}
 
 	return ret;
 }
@@ -1875,7 +1878,8 @@
 
 	if (!pmu->get_event_encoding[PFM_OS_NONE]) {
 		DPRINT("PMU %s does not support PFM_OS_NONE\n", pmu->name);
-		return PFM_ERR_NOTSUPP;
+		ret = PFM_ERR_NOTSUPP;
+		goto error;
 	}
 
 	ret = pmu->get_event_encoding[PFM_OS_NONE](pmu, &e);
Index: src/libpfm4/lib/pfmlib_perf_event.c
===================================================================
RCS file: /depot/devenv/bullxde/perftools/papi_repo/papi/src/libpfm4/lib/pfmlib_perf_event.c,v
retrieving revision 1.10
diff -u -r1.10 pfmlib_perf_event.c
--- src/libpfm4/lib/pfmlib_perf_event.c	30 Jul 2014 17:15:04 -0000	1.10
+++ src/libpfm4/lib/pfmlib_perf_event.c	9 Feb 2015 20:05:17 -0000
@@ -179,19 +179,25 @@
 			has_plm = 1;
 			break;
 		case PERF_ATTR_PE:
-			if (!ival || attr->freq)
-				return PFM_ERR_ATTR_VAL;
+			if (!ival || attr->freq) {
+				ret = PFM_ERR_ATTR_VAL;
+				goto done;
+			}
 			attr->sample_period = ival;
 			break;
 		case PERF_ATTR_FR:
-			if (!ival || attr->sample_period)
-				return PFM_ERR_ATTR_VAL;
+			if (!ival || attr->sample_period) {
+				ret = PFM_ERR_ATTR_VAL;
+				goto done;
+			}
 			attr->sample_freq = ival;
 			attr->freq = 1;
 			break;
 		case PERF_ATTR_PR:
-			if (ival > 3)
-				return PFM_ERR_ATTR_VAL;
+			if (ival > 3) {
+				ret = PFM_ERR_ATTR_VAL;
+				goto done;
+			}
 			attr->precise_ip = ival;
 			break;
 		case PERF_ATTR_EX:
@@ -207,8 +213,10 @@
 			has_vmx_plm = 1;
 			break;
 		case PERF_ATTR_CPU:
-			if (ival >= INT_MAX)
-				return PFM_ERR_ATTR_VAL;
+			if (ival >= INT_MAX) {
+				ret = PFM_ERR_ATTR_VAL;
+				goto done;
+			}
 			cpu = (int)ival;
 			break;
 		}
@@ -318,6 +326,8 @@
 
 	ret = pfmlib_build_fstr(&e, arg.fstr);
 	if (ret == PFM_SUCCESS)
+		// this memcopy gives the caller back a pointer to malloc space we allocated on the heap
+		// who is supposed to free this space ???
 		memcpy(uarg, &arg, sz);
 
 done:
