about summary refs log tree commit diff
path: root/db2/db
diff options
context:
space:
mode:
Diffstat (limited to 'db2/db')
-rw-r--r--db2/db/db_auto.c8
-rw-r--r--db2/db/db_dispatch.c31
-rw-r--r--db2/db/db_ret.c33
3 files changed, 51 insertions, 21 deletions
diff --git a/db2/db/db_auto.c b/db2/db/db_auto.c
index d40d964542..88bca7b583 100644
--- a/db2/db/db_auto.c
+++ b/db2/db/db_auto.c
@@ -122,7 +122,6 @@ int __db_addrem_log(logp, txnid, ret_lsnp, flags,
  * PUBLIC: int __db_addrem_print
  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
  */
-
 int
 __db_addrem_print(notused1, dbtp, lsnp, notused3, notused4)
 	DB_LOG *notused1;
@@ -312,7 +311,6 @@ int __db_split_log(logp, txnid, ret_lsnp, flags,
  * PUBLIC: int __db_split_print
  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
  */
-
 int
 __db_split_print(notused1, dbtp, lsnp, notused3, notused4)
 	DB_LOG *notused1;
@@ -507,7 +505,6 @@ int __db_big_log(logp, txnid, ret_lsnp, flags,
  * PUBLIC: int __db_big_print
  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
  */
-
 int
 __db_big_print(notused1, dbtp, lsnp, notused3, notused4)
 	DB_LOG *notused1;
@@ -678,7 +675,6 @@ int __db_ovref_log(logp, txnid, ret_lsnp, flags,
  * PUBLIC: int __db_ovref_print
  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
  */
-
 int
 __db_ovref_print(notused1, dbtp, lsnp, notused3, notused4)
 	DB_LOG *notused1;
@@ -842,7 +838,6 @@ int __db_relink_log(logp, txnid, ret_lsnp, flags,
  * PUBLIC: int __db_relink_print
  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
  */
-
 int
 __db_relink_print(notused1, dbtp, lsnp, notused3, notused4)
 	DB_LOG *notused1;
@@ -1005,7 +1000,6 @@ int __db_addpage_log(logp, txnid, ret_lsnp, flags,
  * PUBLIC: int __db_addpage_print
  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
  */
-
 int
 __db_addpage_print(notused1, dbtp, lsnp, notused3, notused4)
 	DB_LOG *notused1;
@@ -1180,7 +1174,6 @@ int __db_debug_log(logp, txnid, ret_lsnp, flags,
  * PUBLIC: int __db_debug_print
  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
  */
-
 int
 __db_debug_print(notused1, dbtp, lsnp, notused3, notused4)
 	DB_LOG *notused1;
@@ -1335,7 +1328,6 @@ int __db_noop_log(logp, txnid, ret_lsnp, flags)
  * PUBLIC: int __db_noop_print
  * PUBLIC:    __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
  */
-
 int
 __db_noop_print(notused1, dbtp, lsnp, notused3, notused4)
 	DB_LOG *notused1;
diff --git a/db2/db/db_dispatch.c b/db2/db/db_dispatch.c
index a4bcdb7628..4f89d2b917 100644
--- a/db2/db/db_dispatch.c
+++ b/db2/db/db_dispatch.c
@@ -43,7 +43,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)db_dispatch.c	10.6 (Sleepycat) 10/25/97";
+static const char sccsid[] = "@(#)db_dispatch.c	10.7 (Sleepycat) 11/23/97";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -236,8 +236,8 @@ __db_txnlist_find(listp, txnid)
 	void *listp;
 	u_int32_t txnid;
 {
-	__db_txnlist *p;
 	__db_txnhead *hp;
+	__db_txnlist *p;
 
 	if ((hp = (struct __db_txnhead *)listp) == NULL)
 		return (DB_NOTFOUND);
@@ -255,12 +255,16 @@ __db_txnlist_find(listp, txnid)
 }
 
 #ifdef DEBUG
+/*
+ * __db_txnlist_print --
+ *	Print out the transaction list.
+ */
 void
 __db_txnlist_print(listp)
 	void *listp;
 {
-	__db_txnlist *p;
 	__db_txnhead *hp;
+	__db_txnlist *p;
 
 	hp = (struct __db_txnhead *)listp;
 	printf("Maxid: %lu\n", (u_long)hp->maxid);
@@ -268,3 +272,24 @@ __db_txnlist_print(listp)
 		printf("TXNID: %lu\n", (u_long)p->txnid);
 }
 #endif
+
+/*
+ * __db_txnlist_end --
+ *	Discard transaction linked list.
+ *
+ * PUBLIC: void __db_txnlist_end __P((void *));
+ */
+void
+__db_txnlist_end(listp)
+	void *listp;
+{
+	__db_txnhead *hp;
+	__db_txnlist *p;
+
+	hp = (struct __db_txnhead *)listp;
+	while ((p = LIST_FIRST(&hp->head)) != LIST_END(&hp->head)) {
+		LIST_REMOVE(p, links);
+		__db_free(p);
+	}
+	__db_free(listp);
+}
diff --git a/db2/db/db_ret.c b/db2/db/db_ret.c
index bcec308b95..65441aa45a 100644
--- a/db2/db/db_ret.c
+++ b/db2/db/db_ret.c
@@ -8,7 +8,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)db_ret.c	10.8 (Sleepycat) 10/25/97";
+static const char sccsid[] = "@(#)db_ret.c	10.10 (Sleepycat) 11/28/97";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -116,35 +116,48 @@ __db_retcopy(dbt, data, len, memp, memsize, db_malloc)
 	dbt->size = len;
 
 	/*
-	 * Allocate any necessary memory.
+	 * Allocate memory to be owned by the application: DB_DBT_MALLOC.
 	 *
-	 * XXX: Never allocate 0 bytes.
+	 * !!!
+	 * We always allocate memory, even if we're copying out 0 bytes. This
+	 * guarantees consistency, i.e., the application can always free memory
+	 * without concern as to how many bytes of the record were requested.
+	 *
+	 * XXX
+	 * Never allocate 0 bytes, it's known to make malloc/realloc unhappy.
+	 *
+	 * Use the memory specified by the application: DB_DBT_USERMEM.
+	 *
+	 * !!!
+	 * If the length we're going to copy is 0, the application-supplied
+	 * memory pointer is allowed to be NULL.
 	 */
 	if (F_ISSET(dbt, DB_DBT_MALLOC)) {
 		dbt->data = db_malloc == NULL ?
-		    (void *)__db_malloc(len + 1) :
+		    (void *)__db_malloc(len) :
 		    (void *)db_malloc(len + 1);
 		if (dbt->data == NULL)
 			return (ENOMEM);
 	} else if (F_ISSET(dbt, DB_DBT_USERMEM)) {
-		if (dbt->ulen < len)
+		if (len != 0 && (dbt->data == NULL || dbt->ulen < len))
 			return (ENOMEM);
 	} else if (memp == NULL || memsize == NULL) {
 		return (EINVAL);
 	} else {
-		if (*memsize == 0 || *memsize < len) {
+		if (len != 0 && (*memsize == 0 || *memsize < len)) {
 			*memp = *memp == NULL ?
-			    (void *)__db_malloc(len + 1) :
-			    (void *)__db_realloc(*memp, len + 1);
+			    (void *)__db_malloc(len) :
+			    (void *)__db_realloc(*memp, len);
 			if (*memp == NULL) {
 				*memsize = 0;
 				return (ENOMEM);
 			}
-			*memsize = len + 1;
+			*memsize = len;
 		}
 		dbt->data = *memp;
 	}
 
-	memcpy(dbt->data, data, len);
+	if (len != 0)
+		memcpy(dbt->data, data, len);
 	return (0);
 }