Kbase P111046: Put/Get functions not allowed on uninitialized memory. (2914)
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  12/15/2005 |
|
Status: Unverified
FACT(s) (Environment):
OpenEdge 10.0B
Windows NT 32 Intel/Windows 2000
SonicMQ 5.x
SYMPTOM(s):
Put/Get functions not allowed on uninitialized memory. (2914)
Trying to send and receive XML messages via SonicMQ queue
CAUSE:
Coding error: The MEMPTR variable is uninitialized.
FIX:
Do a SET-SIZE on it before accessing it.
4GL example code:
&ANALYZE-SUSPEND _VERSION-NUMBER AB_v10r12 GUI
&ANALYZE-RESUME
&Scoped-define WINDOW-NAME C-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS C-Win
/*------------------------------------------------------------------------
File:
Description:
Input Parameters:
<none>
Output Parameters:
<none>
Author:
Created:
------------------------------------------------------------------------*/
/* This .W file was created with the Progress AppBuilder. */
/*----------------------------------------------------------------------*/
/* Create an unnamed pool to store all the widgets created
by this procedure. This is a good default which assures
that this procedure's triggers and internal procedures
will execute in this procedure's storage, and that proper
cleanup will occur on deletion of the procedure. */
CREATE WIDGET-POOL.
/* *************************** Definitions ************************** */
/* Parameters Definitions --- */
/* Local Variable Definitions --- */
DEFINE VARIABLE ptpsession AS HANDLE.
DEFINE VARIABLE msgConsumer1 AS HANDLE.
DEFINE VARIABLE stillWaiting AS LOGICAL INIT yes.
DEFINE VARIABLE msgNum AS INT INIT 0.
DEF VAR ds AS CHAR.
DEFINE VARIABLE mesgH AS HANDLE.
DEFINE VARIABLE person AS CHAR INIT "".
DEFINE VARIABLE i AS INT.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
/* ******************** Preprocessor Definitions ******************** */
&Scoped-define PROCEDURE-TYPE Window
&Scoped-define DB-AWARE no
/* Name of designated FRAME-NAME and/or first browse and/or first query */
&Scoped-define FRAME-NAME DEFAULT-FRAME
/* Standard List Definitions */
&Scoped-Define ENABLED-OBJECTS Send Receive EDITOR-1
&Scoped-Define DISPLAYED-OBJECTS EDITOR-1
/* Custom List Definitions */
/* List-1,List-2,List-3,List-4,List-5,List-6 */
/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME
/* ************************ Function Prototypes ********************** */
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD inWait C-Win
FUNCTION inWait RETURNS LOGICAL
( /* parameter-definitions */ ) FORWARD.
/* _UIB-CO.DE-BLOCK-END */
&ANALYZE-RESUME
/* *********************** Control Definitions ********************** */
/* Define the widget handle for the window */
DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO.
/* Definitions of the field level widgets */
DEFINE BUTTON Receive
LABEL "Receive"
SIZE 22 BY 2.38.
DEFINE BUTTON Send
LABEL "Send"
SIZE 20 BY 2.38.
DEFINE VARIABLE EDITOR-1 AS CHARACTER
VIEW-AS EDITOR NO-WORD-WRAP SCROLLBAR-HORIZONTAL SCROLLBAR-VERTICAL
SIZE 60 BY 9.05 NO-UNDO.
/* ************************ Frame Definitions *********************** */
DEFINE FRAME DEFAULT-FRAME
Send AT ROW 1.95 COL 11
Receive AT ROW 1.95 COL 49
EDITOR-1 AT ROW 5.29 COL 11 NO-LABEL
WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
SIDE-LABELS NO-UNDERLINE THREE-D
AT COL 1 ROW 1
SIZE 80 BY 16.
/* *********************** Procedure Settings ************************ */
&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
Type: Window
Allow: Basic,Browse,DB-Fields,Window,Query
Other Settings: COMPILE
*/
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS
/* ************************* Create Window ************************** */
&ANALYZE-SUSPEND _CREATE-WINDOW
IF SESSION:DISPLAY-TYPE = "GUI":U THEN
CREATE WINDOW C-Win ASSIGN
HIDDEN = YES
TITLE = "<insert window title>"
HEIGHT = 16
WIDTH = 80
MAX-HEIGHT = 16
MAX-WIDTH = 80
VIRTUAL-HEIGHT = 16
VIRTUAL-WIDTH = 80
RESIZE = yes
SCROLL-BARS = no
STATUS-AREA = no
BGCOLOR = ?
FGCOLOR = ?
KEEP-FRAME-Z-ORDER = yes
THRE.E-D = yes
MESSAGE-AREA = no
SENSITIVE = yes.
ELSE {&WINDOW-NAME} = CURRENT-WINDOW.
/* END WINDOW DEFINITION */
&ANALYZE-RESUME
/* *********** Runtime Attributes and AppBuilder Settings *********** */
&ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES
/* SETTINGS FOR WINDOW C-Win
VISIBLE,,RUN-PERSISTENT */
/* SETTINGS FOR FRAME DEFAULT-FRAME
FRAME-NAME */
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
THEN C-Win:HIDDEN = no.
/* _RUN-TIME-ATTRIBUTES-END */
&ANALYZE-RESUME
/* ************************ Control Triggers ************************ */
&Scoped-define SELF-NAME C-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win
ON END-ERROR OF C-Win /* <insert window title> */
OR ENDKEY OF {&WINDOW-NAME} ANYWHERE DO:
/* This case occurs when the user presses the "Esc" key.
In a persistently run window, just ignore this. If we did not, the
application would exit. */
IF THIS-PROCEDURE:PERSISTENT THEN RETURN NO-APPLY.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win
ON WINDOW-CLOSE OF C-Win /* <insert window title> */
DO:
/* This event will close the window and terminate the procedure. */
APPLY "CLOSE":U TO THIS-PROCEDURE.
RETURN NO-APPLY.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME Receive
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL Receive C-Win
ON CHOOSE OF Receive IN FRAME DEFAULT-FRAME /* Receive */
DO:
RUN getmessage.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&Scoped-define SELF-NAME Send
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL Send C-Win
ON CHOOSE OF Send IN FRAME DEFAULT-FRAME /* Send */
DO:
RUN sendmessage.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&UNDEFINE SELF-NAME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK C-Win
/* *************************** Main Block *************************** */
/* Set CURRENT-WINDOW: this will parent dialog-boxes and frames. */
ASSIGN CURRENT-WINDOW = {&WINDOW-NAME}
THIS-PROCEDURE:CURRENT-WINDOW = {&WINDOW-NAME}.
/* The CLOSE event can be used from inside or outside the procedure to */
/* terminate it. &nbs.p; */
ON CLOSE OF THIS-PROCEDURE
RUN disable_UI.
/* Best default for GUI applications is... */
PAUSE 0 BEFORE-HIDE.
/* Now enable the interface and wait for the exit condition. */
/* (NOTE: handle ERROR and END-KEY so cleanup code will always fire. */
MAIN-BLOCK:
DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
RUN enable_UI.
IF NOT THIS-PROCEDURE:PERSISTENT THEN
WAIT-FOR CLOSE OF THIS-PROCEDURE.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
/* ********************** Internal Procedures *********************** */
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI C-Win _DEFAULT-DISABLE
PROCEDURE disable_UI :
/*------------------------------------------------------------------------------
Purpose: DISABLE the User Interface
Parameters: <none>
Notes: Here we clean-up the user-interface by deleting
dynamic widgets we have created and/or hide
frames. This procedure is usually called when
we are ready to "clean-up" after running.
------------------------------------------------------------------------------*/
/* Delete the WINDOW we created */
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
THEN DELETE WIDGET C-Win.
IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE enable_UI C-Win _DEFAULT-ENABLE
PROCEDURE enable_UI :
/*------------------------------------------------------------------------------
Purpose: ENABLE the User Interface
Parameters: <none>
Notes: Here we display/view/enable the widgets in the
user-interface. In addition, OPEN all queries
associated with each FRAME and BROWSE.
These statements here are based on the "Other
Settings" section of the widget Property Sheets.
------------------------------------------------------------------------------*/
DISPLAY EDITOR-1
WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
ENABLE Send Receive EDITOR-1
WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
{&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME}
VIEW C-Win.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE getmessage C-Win
PROCEDURE .getmessage :
/*------------------------------------------------------------------------------
Purpose:
Parameters: <none>
Notes:
------------------------------------------------------------------------------*/
RUN jms/ptpsession.p PERSISTENT SET ptpsession ("-H localhost -S 5162 ").
RUN setBrokerURL IN ptpsession ("localhost:2506").
RUN SETUSER IN ptpsession ("Administrator").
RUN setPassword IN ptpsession ("Administrator").
RUN beginSession IN ptpsession.
RUN createMessageConsumer IN ptpsession
(THIS-PROCEDURE, "messageHandler", OUTPUT msgConsumer1).
RUN receiveFromQueue IN ptpsession ("SampleQ1", /* name of queue */
?, /* No message selector */
msgConsumer1). /* Handles incoming messages*/
RUN startReceiveMessages IN ptpsession.
RUN waitForMessages IN ptpsession ("inWait", THIS-PROCEDURE, 5).
RUN deleteSession IN ptpsession.
EDITOR-1:SCREEN-VALUE IN FRAME DEFAULT-FRAME = ds .
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE getPeople C-Win
PROCEDURE getPeople :
/*------------------------------------------------------------------------------
Purpose:
Parameters: <none>
Notes:
------------------------------------------------------------------------------*/
/* Displays the XML node names and XML text. */
DEFINE INPUT PARAMETER hParent AS HANDLE.
DEFINE INPUT PARAMETER level AS INT.
DEFINE VAR i AS INT.
DEFINE VAR hNoderef AS HANDLE.
CREATE X-NODEREF hNoderef.
REPEAT i = 1 TO hParent:NUM-CHILDREN.
hParent:GET-CHILD(hNoderef,i).
IF hNoderef:NAME = "#text" THEN DO:
ds = ds + "Text: " + hNoderef:NODE-VALUE + CHR(10) .
END.
ELSE
ds = ds + " Node name: " + hNoderef:NAME .
RUN getPeople(hNoderef, (level + 1)).
END.
DELETE OBJECT hNoderef.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE messageHandler C-Win
PROCEDURE messageHandler :
/*------------------------------------------------------------------------------
Purpose:
Parameters: <none>
Notes:
------------------------------------------------------------------------------*/
DEFINE INPUT PARAMETER messageH AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER messageConsumerH AS HANDLE NO-UNDO.
DEFINE OUTPUT PARAMETER replyH AS HANDLE NO-UNDO.
DEFINE VAR memptrDoc AS MEMPTR.
DEFINE VAR hdoc AS HANDLE.
DEFINE VAR hRoot AS HANDLE.
DEFINE VAR xmlText AS CHAR.
DEFINE VAR indx AS INT.
CREATE X-DOCUMENT hdoc.
CREATE X-NODEREF hRoot.
SET-SIZE(memptrDoc) = 400000. /* The size is an estimate. */
indx = 1.
DO WHILE NOT DYNAMIC-FUNCTION('endOfStream' IN messageH):
xmlText = DYNAMIC-FUNCTION('getTextSegmen.t':U IN messageH).
PUT-STRING(memptrDoc, indx) = xmlText.
indx = indx + LENGTH(xmlText).
END.
hdoc:LOAD("memptr", memptrDoc, FALSE).
hdoc:GET-DOCUMENT-ELEMENT(hRoot).
RUN getPeople(hRoot, 1).
RUN deleteMessage IN messageH.
SET-SIZE(memptrDoc) = 0.
stillWaiting = false.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE sendmessage C-Win
PROCEDURE sendmessage :
/*------------------------------------------------------------------------------
Purpose:
Parameters: <none>
Notes:
------------------------------------------------------------------------------*/
RUN jms/ptpsession.p PERSISTENT SET ptpsession ("-H localhost -S 5162 ").
RUN setBrokerURL IN ptpsession ("localhost:2506").
RUN SETUSER IN ptpsession ("Administrator").
RUN setPassword IN ptpsession ("Administrator").
RUN beginSession IN ptpsession.
RUN createXMLMessage IN ptpsession (OUTPUT mesgH).
/* Creates an XML message with 100 people. */
RUN appendText IN mesgH('<?xml version="1.0" ').
RUN appendText IN mesgH("encoding='ISO8859-1' ?>").
RUN appendText IN mesgH("<personnel>").
REPEAT i = 1 TO 100:
person = "<person>".
person = person + "<name>".
person = person + "<family>SecondName</family>".
person = person + "<given>FirstName" + STRING(i) + "</given>".
person = person + "<
ame>".
person = person + "<email>myEmail@subpargolf.com</email>".
person = person + "</person>".
RUN appendText IN mesgH(person).
END.
RUN appendText IN mesgH("</personnel>").
RUN sendToQueue IN ptpsession ("SampleQ1", mesgH, ?, ?, ?) NO-ERROR.
RUN deleteMessage IN mesgH.
RUN deleteSession IN ptpsession.
EDITOR-1:SCREEN-VALUE IN FRAME DEFAULT-FRAME = "MESSAGE sent succesfully." .
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
/* ************************ Function Implementations ***************** */
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION inWait C-Win
FUNCTION inWait RETURNS LOGICAL
( /* parameter-definitions */ ) :
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
RETURN stillWaiting.
END FUNCTION.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
.