diff --git a/man/man3/pmdatext.3 b/man/man3/pmdatext.3 index 503e5f3..a4700cf 100644 --- a/man/man3/pmdatext.3 +++ b/man/man3/pmdatext.3 @@ -89,12 +89,10 @@ for the full help text. .PP The .I buffer -is allocated using -.BR malloc (3) -and should be released by the caller of -.B pmdaText -with a call to -.BR free (3). +is managed internally and should +.B not +be released or freed by the caller of +.BR pmdaText . .SH DIAGNOSTICS If the requested help text could not be obtained, diff --git a/src/dbpmda/src/dso.c b/src/dbpmda/src/dso.c index 7c52296..4393447 100644 --- a/src/dbpmda/src/dso.c +++ b/src/dbpmda/src/dso.c @@ -464,7 +464,9 @@ dodso(int pdu) printf("%s\n", buffer); else printf("\n"); - free(buffer); + /* only PMDA_INTERFACE_1 uses a malloc'd buffer */ + if (dispatch.comm.pmda_interface == PMDA_INTERFACE_1) + free(buffer); } else { if (dispatch.comm.pmapi_version == PMAPI_VERSION_1) diff --git a/src/libpcp/src/help.c b/src/libpcp/src/help.c index 5046603..eebce9d 100644 --- a/src/libpcp/src/help.c +++ b/src/libpcp/src/help.c @@ -105,8 +105,11 @@ again_local: type |= PM_TEXT_ONELINE; goto again_local; } - if (n == 0) { - /* PMDAs don't allocate this space, but the caller will free it */ + if (n == 0 && dp->dispatch.comm.pmda_interface != PMDA_INTERFACE_1) { + /* + * PMDAs after PMDA_INTERFACE_1 don't malloc the buffer + * but the caller will free it + */ *buffer = strdup(*buffer); } else if (n < 0 && dp->dispatch.comm.pmapi_version == PMAPI_VERSION_1) { diff --git a/src/libpcp_pmda/src/libdefs.h b/src/libpcp_pmda/src/libdefs.h index e91f703..91546fd 100644 --- a/src/libpcp_pmda/src/libdefs.h +++ b/src/libpcp_pmda/src/libdefs.h @@ -19,6 +19,7 @@ #ifndef LIBDEFS_H #define LIBDEFS_H +#define HAVE_V_ONE(interface) (interface == PMDA_INTERFACE_1) #define HAVE_V_TWO(interface) (interface == PMDA_INTERFACE_2 || interface == PMDA_INTERFACE_3) #define HAVE_V_FOUR(interface) (interface == PMDA_INTERFACE_4) diff --git a/src/libpcp_pmda/src/mainloop.c b/src/libpcp_pmda/src/mainloop.c index b6333b6..445be7f 100644 --- a/src/libpcp_pmda/src/mainloop.c +++ b/src/libpcp_pmda/src/mainloop.c @@ -363,8 +363,12 @@ __pmdaMainPDU(pmdaInterface *dispatch) } if (sts < 0) __pmSendError(pmda->e_outfd, PDU_BINARY, sts); - else + else { __pmSendText(pmda->e_outfd, PDU_BINARY, ident, buffer); + /* only PMDA_INTERFACE_1 malloc's the buffer */ + if (HAVE_V_ONE(dispatch->comm.pmda_interface)) + free(buffer); + } break; case PDU_RESULT: