@@ -1172,7 +1172,6 @@ func (handle *MQMessageHandle) DltMP(godmpo *MQDMPO, name string) error {
11721172/*
11731173InqMP is the function to inquire about the value of a message property.
11741174*/
1175-
11761175func (handle * MQMessageHandle ) InqMP (goimpo * MQIMPO , gopd * MQPD , name string ) (string , interface {}, error ) {
11771176 var mqrc C.MQLONG
11781177 var mqcc C.MQLONG
@@ -1198,11 +1197,18 @@ func (handle *MQMessageHandle) InqMP(goimpo *MQIMPO, gopd *MQPD, name string) (s
11981197 mqName .VSPtr = (C .MQPTR )(C .malloc (namebufsize ))
11991198 mqName .VSBufSize = namebufsize
12001199 }
1200+ // VSPtr is either explicit malloc or comes from CString which does a
1201+ // malloc. Either way, the buffer should be freed at the end.
1202+ defer C .free (unsafe .Pointer (mqName .VSPtr ))
12011203
12021204 copyIMPOtoC (& mqimpo , goimpo )
12031205 copyPDtoC (& mqpd , gopd )
12041206
1207+ // Use a local buffer instead of something global so we don't
1208+ // have to worry about multiple threads accessing it.
12051209 propertyPtr = C .PMQVOID (C .malloc (propbufsize ))
1210+ defer C .free (unsafe .Pointer (propertyPtr ))
1211+
12061212 bufferLength := C .MQLONG (namebufsize )
12071213
12081214 C .MQINQMP (handle .qMgr .hConn ,
@@ -1217,10 +1223,6 @@ func (handle *MQMessageHandle) InqMP(goimpo *MQIMPO, gopd *MQPD, name string) (s
12171223 & mqcc ,
12181224 & mqrc )
12191225
1220- if len (name ) > 0 {
1221- C .free (unsafe .Pointer (mqName .VSPtr ))
1222- }
1223-
12241226 mqreturn := MQReturn {MQCC : int32 (mqcc ),
12251227 MQRC : int32 (mqrc ),
12261228 verb : "MQINQMP" ,
@@ -1238,7 +1240,7 @@ func (handle *MQMessageHandle) InqMP(goimpo *MQIMPO, gopd *MQPD, name string) (s
12381240 p := (* C .MQBYTE )(propertyPtr )
12391241 propertyValue = (int8 )(* p )
12401242 case C .MQTYPE_INT16 :
1241- p := (* C .MQBYTE )(propertyPtr )
1243+ p := (* C .MQINT16 )(propertyPtr )
12421244 propertyValue = (int16 )(* p )
12431245 case C .MQTYPE_INT32 :
12441246 p := (* C .MQINT32 )(propertyPtr )
0 commit comments