Memory Leak Concern

I am supporting code that uses a PxLoadImage() call to read an image file
off disk and install it as a background image. The image changes frequently
and the original designers did not want to embed it in a Data Base widget.

A BIG memory leak of the image data drew me to look closer at this code.

Original code:
memset(&methods, 0, sizeof(PxMethods_t));
methods.flags |= PX_DIRECT_COLOR;
methods.flags |= PX_DODITHER;
methods.flags |= PX_SUPPRESS_TAG;

splash_image = PxLoadImage(F_SPLASH_IMAGE_PATH, &methods);

PtSetArg(&args[0], Pt_ARG_BKGD_IMAGE, splash_image,
sizeof(*splash_image) );
PtSetResources(ABW_BaseBkgd, 1, args);

Modified code:
splash_image = PxLoadImage(F_SPLASH_IMAGE_PATH, &methods);
(*splash_image).flags |= Ph_RELEASE_IMAGE;

PtSetArg(&args[0], Pt_ARG_BKGD_IMAGE, splash_image,
sizeof(*splash_image));
PtSetResources(ABW_BaseBkgd, 1, args);

The above change allowed the widget to release the image and solved my
immediate resource problem.

While the examples don’t show it, it seems like splash_image should be
freed also.

  1. Should the PhImage_t * be freed?


    To complicate the issue, I have the same problem with Data Base images.
    While I know not to release the image which is owned by the Data Base, I am
    allowing the widget to release the transparency mask which is built.

Original code:
warning_image = ApGetImageRes(gTextDbPtr, “ImageYellowWarningTriangle”);
PhMakeTransBitmap(warning_image, Pg_WHITE);

PtSetArg(&args[0], Pt_ARG_LABEL_DATA, warning_image,
sizeof(*warning_image));
PtSetResources(ABW_SplashWarningTriangleLbl, 1, args);


Modified code:
warning_image = ApGetImageRes(gTextDbPtr, “ImageYellowWarningTriangle”);
PhMakeTransBitmap(warning_image, Pg_WHITE);
(*warning_image).flags |= Ph_RELEASE_TRANSPARENCY_MASK;

PtSetArg(&args[0], Pt_ARG_LABEL_DATA, warning_image,
sizeof(*warning_image));
PtSetResources(ABW_SplashWarningTriangleLbl, 1, args);

  1. Should warning_image be freed?


    To complicate the issue still more, I looked at help for ApGetBitmapRes().
    That help says never release the pointer as it is a part of the Data Base.
    Then I found ApFreeBitmapRes() which claims to free structures received
    from ApGetBitmapRes().

  2. I’m melting, I’m melting.



    TIA
    Jan




    Jan Stefan
    Software Engineer

jstefan@minnetronix.com
www.minnetronix.com

Minnetronix Inc.
1635 Energy Park Drive
St. Paul, MN 55108

phone: (651) 917-4060 ext. 256