<pre style='margin:0'>
Joshua Root (jmroot) pushed a commit to branch master
in repository macports-base.

</pre>
<p><a href="https://github.com/macports/macports-base/commit/424c52db20684d986a4678b0c79ea9e63986b625">https://github.com/macports/macports-base/commit/424c52db20684d986a4678b0c79ea9e63986b625</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 424c52db20684d986a4678b0c79ea9e63986b625
</span>Author: Joshua Root <jmr@macports.org>
AuthorDate: Sun Jun 13 17:53:13 2021 +1000

<span style='display:block; white-space:pre;color:#404040;'>    Free portgroup objects when detaching registry
</span>---
 src/cregistry/portgroup.c  | 28 ++++++++++++++++++++++++++++
 src/cregistry/portgroup.h  |  1 +
 src/cregistry/registry.c   | 15 +++++++++++++--
 src/registry2.0/registry.c | 29 +++++++++++++++++++++--------
 4 files changed, 63 insertions(+), 10 deletions(-)

<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/portgroup.c b/src/cregistry/portgroup.c
</span><span style='display:block; white-space:pre;color:#808080;'>index ab2942a8..3fb59786 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/portgroup.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/portgroup.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -315,3 +315,31 @@ reg_portgroup* reg_portgroup_open(reg_registry* reg, char *id, char* name, char*
</span>     }
     return portgroup;
 }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/**
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Fetches a list of all open portgroups.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [in] reg      registry to fetch portgroups from
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [out] portgroups a list of open portgroups
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @return              the number of open portgroups, -1 on error
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_all_open_portgroups(reg_registry* reg, reg_portgroup*** portgroups) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    reg_portgroup* portgroup;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    int portgroup_count = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    int portgroup_space = 10;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    Tcl_HashEntry* hash;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    Tcl_HashSearch search;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    *portgroups = malloc(portgroup_space * sizeof(reg_portgroup*));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if (!*portgroups) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    for (hash = Tcl_FirstHashEntry(&reg->open_portgroups, &search); hash != NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            hash = Tcl_NextHashEntry(&search)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        portgroup = Tcl_GetHashValue(hash);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if (!reg_listcat((void***)portgroups, &portgroup_count, &portgroup_space, portgroup)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            free(*portgroups);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    return portgroup_count;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/portgroup.h b/src/cregistry/portgroup.h
</span><span style='display:block; white-space:pre;color:#808080;'>index b432c45c..0d34d1c5 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/portgroup.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/portgroup.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -51,5 +51,6 @@ int reg_portgroup_propget(reg_portgroup* portgroup, char* key, char** value,
</span>         reg_error* errPtr);
 int reg_portgroup_propset(reg_portgroup* portgroup, char* key, char* value,
         reg_error* errPtr);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_all_open_portgroups(reg_registry* reg, reg_portgroup*** portgroups);
</span> 
 #endif /* _CPORTGROUP_H */
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/registry.c b/src/cregistry/registry.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 5b4a8257..68c6d3bf 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/registry.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/registry.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -310,7 +310,6 @@ int reg_detach(reg_registry* reg, reg_error* errPtr) {
</span>     }
     if (sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
         int r;
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        reg_entry* entry;
</span>         Tcl_HashEntry* curr;
         Tcl_HashSearch search;
         /* XXX: Busy waiting, consider using sqlite3_busy_handler/timeout */
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -321,13 +320,14 @@ int reg_detach(reg_registry* reg, reg_error* errPtr) {
</span>                 case SQLITE_OK:
                     for (curr = Tcl_FirstHashEntry(&reg->open_entries, &search);
                             curr != NULL; curr = Tcl_NextHashEntry(&search)) {
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        entry = Tcl_GetHashValue(curr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        reg_entry* entry = Tcl_GetHashValue(curr);
</span>                         if (entry->proc) {
                             free(entry->proc);
                         }
                         free(entry);
                     }
                     Tcl_DeleteHashTable(&reg->open_entries);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span>                     for (curr = Tcl_FirstHashEntry(&reg->open_files, &search);
                             curr != NULL; curr = Tcl_NextHashEntry(&search)) {
                         reg_file* file = Tcl_GetHashValue(curr);
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -342,6 +342,17 @@ int reg_detach(reg_registry* reg, reg_error* errPtr) {
</span>                         free(file);
                     }
                     Tcl_DeleteHashTable(&reg->open_files);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    for (curr = Tcl_FirstHashEntry(&reg->open_portgroups, &search);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            curr != NULL; curr = Tcl_NextHashEntry(&search)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        reg_portgroup* portgroup = Tcl_GetHashValue(curr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        if (portgroup->proc) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            free(portgroup->proc);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        free(portgroup);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    Tcl_DeleteHashTable(&reg->open_portgroups);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span>                     reg->status &= ~reg_attached;
                     result = 1;
                     break;
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/registry2.0/registry.c b/src/registry2.0/registry.c
</span><span style='display:block; white-space:pre;color:#808080;'>index f9bfad9a..336b19fb 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/registry2.0/registry.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/registry2.0/registry.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -85,29 +85,42 @@ int registry_tcl_detach(Tcl_Interp* interp, reg_registry* reg,
</span>         reg_error* errPtr) {
     reg_entry** entries;
     reg_file** files;
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    int entry_count;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    int file_count;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    reg_portgroup** portgroups;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    int count;
</span>     int i;
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    entry_count = reg_all_open_entries(reg, &entries);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    if (entry_count == -1) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    count = reg_all_open_entries(reg, &entries);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if (count == -1) {
</span>         return 0;
     }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    for (i=0; i<entry_count; i++) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    for (i = 0; i < count; i++) {
</span>         if (entries[i]->proc) {
             Tcl_DeleteCommand(interp, entries[i]->proc);
         }
     }
     free(entries);
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    file_count = reg_all_open_files(reg, &files);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    if (file_count == -1) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    count = reg_all_open_files(reg, &files);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if (count == -1) {
</span>         return 0;
     }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    for (i = 0; i < file_count; i++) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    for (i = 0; i < count; i++) {
</span>         if (files[i]->proc) {
             Tcl_DeleteCommand(interp, files[i]->proc);
         }
     }
     free(files);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    count = reg_all_open_portgroups(reg, &portgroups);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if (count == -1) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    for (i = 0; i < count; i++) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if (portgroups[i]->proc) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            Tcl_DeleteCommand(interp, portgroups[i]->proc);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    free(portgroups);
</span>     if (!reg_detach(reg, errPtr)) {
         return registry_failed(interp, errPtr);
     }
</pre><pre style='margin:0'>

</pre>