|
-
July 15th, 2002, 01:07 PM
#1
Memory leak with lParam
I have a problem with memory leaks using lParam. I am using a Tree control, and when adding an item, I set the lParam to a variable using char*. However, if I free that char*, the lParam value is gone later on. Using strdup works, but causes memory leaks after closing the application.
cdir is a std::string which as an example, will have a value of
"c:\zrbite\programs"
char* temp = strdup(cdir.c_str());
TVITEM item;
TVINSERTSTRUCT itemstr;
item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
item.lParam = (LPARAM) (LPCTSTR) temp;
item.pszText = title;
item.iImage = 1;
item.iSelectedImage = 1;
itemstr.hParent = parent.hItem;
itemstr.item = item;
CtlDir.InsertItem(&itemstr);
free(temp);
The lParam doesn't work because temp is freed. However, having strdup(temp) to set lParam causes a memory leak also.
-
November 22nd, 2004, 01:21 AM
#2
Re: Memory leak with lParam
Of course you cannot access the data, since it's local.
You have to new a memory for that lparam, and then free them when you are going to terminate the program (control).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|