Index: macosx/tclMacOSXBundle.c
===================================================================
RCS file: /cvsroot/tcl/tcl/macosx/tclMacOSXBundle.c,v
retrieving revision 1.11.4.3
diff -u -p -r1.11.4.3 tclMacOSXBundle.c
--- macosx/tclMacOSXBundle.c	14 Apr 2009 00:55:34 -0000	1.11.4.3
+++ macosx/tclMacOSXBundle.c	5 Oct 2009 02:30:25 -0000
@@ -55,7 +55,8 @@ extern char *dlerror(void) WEAK_IMPORT_A
 #include <mach-o/dyld.h>
 #endif
 
-#if TCL_DYLD_USE_DLFCN && MAC_OS_X_VERSION_MIN_REQUIRED < 1040
+#if (TCL_DYLD_USE_DLFCN && MAC_OS_X_VERSION_MIN_REQUIRED < 1040) || \
+	(MAC_OS_X_VERSION_MIN_REQUIRED < 1050)
 MODULE_SCOPE long tclMacOSXDarwinRelease;
 #endif
 
@@ -157,17 +158,16 @@ Tcl_MacOSXOpenVersionedBundleResources(
 		    bundleVersion, kCFStringEncodingUTF8);
 
 	    if (bundleVersionRef) {
+		CFComparisonResult versionComparison = kCFCompareLessThan;
 		CFStringRef bundleTailRef = CFURLCopyLastPathComponent(
 			bundleURL);
 
 		if (bundleTailRef) {
-		    if (CFStringCompare(bundleTailRef, bundleVersionRef, 0) ==
-			    kCFCompareEqualTo) {
-			versionedBundleRef = (CFBundleRef) CFRetain(bundleRef);
-		    }
+		    versionComparison = CFStringCompare(bundleTailRef,
+			    bundleVersionRef, 0);
 		    CFRelease(bundleTailRef);
 		}
-		if (!versionedBundleRef) {
+		if (versionComparison != kCFCompareEqualTo) {
 		    CFURLRef versURL = CFURLCreateCopyAppendingPathComponent(
 			    NULL, bundleURL, CFSTR("Versions"), TRUE);
 
@@ -175,9 +175,13 @@ Tcl_MacOSXOpenVersionedBundleResources(
 			CFURLRef versionedBundleURL =
 				CFURLCreateCopyAppendingPathComponent(
 				NULL, versURL, bundleVersionRef, TRUE);
+
 			if (versionedBundleURL) {
 			    versionedBundleRef = CFBundleCreate(NULL,
 				    versionedBundleURL);
+			    if (versionedBundleRef) {
+				bundleRef = versionedBundleRef;
+			    }
 			    CFRelease(versionedBundleURL);
 			}
 			CFRelease(versURL);
@@ -187,9 +191,6 @@ Tcl_MacOSXOpenVersionedBundleResources(
 	    }
 	    CFRelease(bundleURL);
 	}
-	if (versionedBundleRef) {
-	    bundleRef = versionedBundleRef;
-	}
     }
 
     if (bundleRef) {
@@ -258,7 +259,13 @@ Tcl_MacOSXOpenVersionedBundleResources(
 	    CFRelease(libURL);
 	}
 	if (versionedBundleRef) {
-	    CFRelease(versionedBundleRef);
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
+	    /* Workaround CFBundle bug in Tiger and earlier. [Bug 2569449] */
+	    if (tclMacOSXDarwinRelease >= 9)
+#endif
+	    {
+		CFRelease(versionedBundleRef);
+	    }
 	}
     }
 
Index: unix/tclUnixInit.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixInit.c,v
retrieving revision 1.82
diff -u -p -r1.82 tclUnixInit.c
--- unix/tclUnixInit.c	13 Dec 2007 15:28:42 -0000	1.82
+++ unix/tclUnixInit.c	5 Oct 2009 02:30:25 -0000
@@ -335,10 +335,11 @@ static int		MacOSXGetLibraryPath(Tcl_Int
 			    int maxPathLen, char *tclLibPath);
 #endif /* HAVE_COREFOUNDATION */
 #if defined(__APPLE__) && (defined(TCL_LOAD_FROM_MEMORY) || ( \
-	defined(TCL_THREADS) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
-	MAC_OS_X_VERSION_MIN_REQUIRED < 1030) || ( \
-	defined(__LP64__) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
-	MAC_OS_X_VERSION_MIN_REQUIRED < 1050))
+	defined(MAC_OS_X_VERSION_MIN_REQUIRED) && ( \
+	(defined(TCL_THREADS) && MAC_OS_X_VERSION_MIN_REQUIRED < 1030) || \
+	(defined(__LP64__) && MAC_OS_X_VERSION_MIN_REQUIRED < 1050) || \
+	(defined(HAVE_COREFOUNDATION) && MAC_OS_X_VERSION_MIN_REQUIRED < 1050)\
+	)))
 /*
  * Need to check Darwin release at runtime in tclUnixFCmd.c and tclLoadDyld.c:
  * initialize release global at startup from uname().
