@@ -783,13 +783,12 @@ Tcl_UnloadObjCmd(
783
783
*/
784
784
static int
785
785
UnloadLibrary (
786
- Tcl_Interp * interp ,
787
- Tcl_Interp * target ,
788
- LoadedLibrary * libraryPtr ,
789
- int keepLibrary ,
790
- const char * fullFileName ,
791
- int interpExiting
792
- )
786
+ Tcl_Interp * interp ,
787
+ Tcl_Interp * target ,
788
+ LoadedLibrary * libraryPtr ,
789
+ int keepLibrary ,
790
+ const char * fullFileName ,
791
+ int interpExiting )
793
792
{
794
793
int code ;
795
794
InterpLibrary * ipFirstPtr , * ipPtr ;
@@ -877,24 +876,27 @@ UnloadLibrary(
877
876
* Remove this library from the interpreter's library cache.
878
877
*/
879
878
880
- ipFirstPtr = (InterpLibrary * )Tcl_GetAssocData (target , "tclLoad" , NULL );
881
- ipPtr = ipFirstPtr ;
882
- if (ipPtr -> libraryPtr == libraryPtr ) {
883
- ipFirstPtr = ipFirstPtr -> nextPtr ;
884
- } else {
885
- InterpLibrary * ipPrevPtr ;
886
-
887
- for (ipPrevPtr = ipPtr ; ipPtr != NULL ;
888
- ipPrevPtr = ipPtr , ipPtr = ipPtr -> nextPtr ) {
879
+ if (!interpExiting ) {
880
+ ipFirstPtr = (InterpLibrary * )Tcl_GetAssocData (target , "tclLoad" , NULL );
881
+ if (ipFirstPtr ) {
882
+ ipPtr = ipFirstPtr ;
889
883
if (ipPtr -> libraryPtr == libraryPtr ) {
890
- ipPrevPtr -> nextPtr = ipPtr -> nextPtr ;
891
- break ;
884
+ ipFirstPtr = ipFirstPtr -> nextPtr ;
885
+ } else {
886
+ InterpLibrary * ipPrevPtr ;
887
+
888
+ for (ipPrevPtr = ipPtr ; ipPtr != NULL ;
889
+ ipPrevPtr = ipPtr , ipPtr = ipPtr -> nextPtr ) {
890
+ if (ipPtr -> libraryPtr == libraryPtr ) {
891
+ ipPrevPtr -> nextPtr = ipPtr -> nextPtr ;
892
+ break ;
893
+ }
894
+ }
892
895
}
896
+ ckfree (ipPtr );
897
+ Tcl_SetAssocData (target , "tclLoad" , LoadCleanupProc , ipFirstPtr );
893
898
}
894
899
}
895
- ckfree (ipPtr );
896
- Tcl_SetAssocData (target , "tclLoad" , LoadCleanupProc , ipFirstPtr );
897
-
898
900
899
901
if (IsStatic (libraryPtr )) {
900
902
goto done ;
@@ -1206,21 +1208,22 @@ TclGetLoadedLibraries(
1206
1208
1207
1209
static void
1208
1210
LoadCleanupProc (
1209
- TCL_UNUSED ( ClientData ) , /* Pointer to first InterpLibrary structure
1211
+ ClientData clientData , /* Pointer to first InterpLibrary structure
1210
1212
* for interp. */
1211
1213
Tcl_Interp * interp )
1212
1214
{
1213
- InterpLibrary * ipPtr ;
1215
+ InterpLibrary * ipPtr = ( InterpLibrary * ) clientData , * nextPtr ;
1214
1216
LoadedLibrary * libraryPtr ;
1215
1217
1216
- while (1 ) {
1217
- ipPtr = (InterpLibrary * )Tcl_GetAssocData (interp , "tclLoad" , NULL );
1218
- if (ipPtr == NULL ) {
1219
- break ;
1220
- }
1218
+ do {
1221
1219
libraryPtr = ipPtr -> libraryPtr ;
1222
- UnloadLibrary (interp , interp , libraryPtr , 0 ,"" , 1 );
1223
- }
1220
+ UnloadLibrary (interp , interp , libraryPtr , 0 , "" , 1 );
1221
+ /* UnloadLibrary doesn't free it by interp delete, so do it here and
1222
+ * repeat for next. */
1223
+ nextPtr = ipPtr -> nextPtr ;
1224
+ ckfree (ipPtr );
1225
+ ipPtr = nextPtr ;
1226
+ } while (ipPtr );
1224
1227
}
1225
1228
1226
1229
/*
0 commit comments