Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Source/CFTree.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CFTreeFinalize (CFTypeRef cf)

release = tree->_context.release;
if (release)
release (tree);
release (tree->_context.info);
}

static CFRuntimeClass CFTreeClass =
Expand Down Expand Up @@ -116,6 +116,9 @@ CFTreeCreate (CFAllocatorRef allocator, const CFTreeContext *context)
if (context == NULL)
context = &_kCFNullTreeContext;
memcpy (&new->_context, context, sizeof(CFTreeContext));
if (new->_context.retain)
new->_context.info =
(void *)new->_context.retain (new->_context.info);
}

return new;
Expand Down
36 changes: 36 additions & 0 deletions Tests/CFTree/context.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <CoreFoundation/CFTree.h>
#include <CoreFoundation/CFString.h>

#include "../CFTesting.h"

int main (void)
{
CFStringRef info;
CFTreeContext ctx;
CFTreeContext out;
CFTreeRef tree;

info = CFStringCreateWithCString (NULL, "node", kCFStringEncodingUTF8);

ctx.version = 0;
ctx.info = (void *)info;
ctx.retain = CFRetain;
ctx.release = CFRelease;
ctx.copyDescription = CFCopyDescription;

tree = CFTreeCreate (NULL, &ctx);
PASS_CF(tree != NULL, "Created a tree with a retaining context.");

CFTreeGetContext (tree, &out);
PASS_CF(out.info == (void *)info, "CFTreeGetContext returns the info.");
PASS_CF(out.retain == CFRetain && out.release == CFRelease,
"CFTreeGetContext returns the context callbacks.");

CFRelease (tree);
PASS_CF(CFStringGetLength (info) == 4,
"The context info outlives the tree that retained it.");

CFRelease (info);

return 0;
}
Loading