Discussion:
[omniORB] Is this a memory leak?
Preston, Ralph A.
2009-10-22 19:47:07 UTC
Permalink
Hello,

Could someone please explain why this is, or isn't, a memory leak. I'm writing this from memory, so if there are any errors (besides the one I'm about to describe) it's due to my faulty memory. As is, the code runs correctly, but I thought I'd have to uncomment line 28 to remove a memory leak, however, when I do that the server crashes. Thanks!

1 // Begin IDL
2
3 struct FileData {
4 string name;
5 };
6
7 typedef sequence<FileData> FileList;
8
9 boolean GetFileList( out FileList list );
10
11 // End IDL
12
13 // BaseClass.cpp
14 ::CORBA::Boolean BaseClass::GetFileList( FileList_out list )
15 {
16 list = new FileList();
17 list->length(1);
18 (*list)[0].name = CORBA::string_dup("BaseClassFile.txt");
19 return 1;
20 }
21 // End BaseClass.cpp
22
23
24 // ChildClass.cpp
25 ::CORBA::Boolean ChildClass::GetFileList( FileList_out list )
26 {
27 BaseClass::GetFileList(list);
28 //CORBA::string_free((*list)[0].name);
29 (*list)[0].name = CORBA::string_dup("ChildClassFile.txt");
30 return 1;
31 }
32 // End ChildClass.cpp


Ralph A. Preston
The MITRE Corporation
202 Burlington Road, MS E095
Bedford, MA 01730
Office: 781-271-7914 Fax: 781-271-8915 Cell: 617-335-2226
Igor Lautar
2009-10-22 19:53:34 UTC
Permalink
Hi,
Post by Preston, Ralph A.
Could someone please explain why this is, or isn't, a memory leak. I'm
writing this from memory, so if there are any errors (besides the one I'm
about to describe) it's due to my faulty memory. As is, the code runs
correctly, but I thought I'd have to uncomment line 28 to remove a memory
leak, however, when I do that the server crashes. Thanks!
It is not a memory leak, as IDL struct string (and other complex types)
members are mapped to 'smart' pointers. Thus when you assign a new value, or
structs destructor is called, member is freed.

Regards,

Loading...