serv_fulltext.c: copy the data returned by cdb_fetch() instead of taking ownership
authorArt Cancro <ajc@citadel.org>
Wed, 16 Aug 2023 02:18:31 +0000 (17:18 -0900)
committerArt Cancro <ajc@citadel.org>
Wed, 16 Aug 2023 02:18:31 +0000 (17:18 -0900)
We have to do this everywhere.  Berkeley DB can be configured to hand off ownership of memory to
the caller, but LMDB cannot.

citadel/server/modules/fulltext/serv_fulltext.c

index 008e4fc60e4abc7f58ba436db2809183f53ac46c..e1558f445cbf4b5d6cb8535f5751c474824c2391 100644 (file)
@@ -130,8 +130,8 @@ void ft_index_message(long msgnum, int op) {
                                        cdb_bucket = cdb_fetch(CDB_FULLTEXT, &tok, sizeof(int));
                                        if (cdb_bucket != NULL) {
                                                ftc_num_msgs[tok] = cdb_bucket->len / sizeof(long);
-                                               ftc_msgs[tok] = (long *)cdb_bucket->ptr;
-                                               cdb_bucket->ptr = NULL;         // (this needs attention if we move to LMDB)
+                                               ftc_msgs[tok] = malloc(cdb_bucket->len);
+                                               memcpy(ftc_msgs[tok], cdb_bucket->ptr, cdb_bucket->len);
                                                cdb_free(cdb_bucket);
                                        }
                                        else {
@@ -140,7 +140,6 @@ void ft_index_message(long msgnum, int op) {
                                        }
                                }
        
-       
                                if (op == 1) {  // add to index
                                        ++ftc_num_msgs[tok];
                                        ftc_msgs[tok] = realloc(ftc_msgs[tok], ftc_num_msgs[tok]*sizeof(long));
@@ -314,8 +313,8 @@ void ft_search(int *fts_num_msgs, long **fts_msgs, const char *search_string) {
                                cdb_bucket = cdb_fetch(CDB_FULLTEXT, &tok, sizeof(int));
                                if (cdb_bucket != NULL) {
                                        ftc_num_msgs[tok] = cdb_bucket->len / sizeof(long);
-                                       ftc_msgs[tok] = (long *)cdb_bucket->ptr;
-                                       cdb_bucket->ptr = NULL;                 // (this needs attention if we move to LMDB)
+                                       ftc_msgs[tok] = (long *) malloc(cdb_bucket->len);
+                                       memcpy(ftc_msgs[tok], cdb_bucket->ptr, cdb_bucket->len);
                                        cdb_free(cdb_bucket);
                                }
                                else {