]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Replace MEM_DREAD_CTRL pool with MEMPROXY class pool (#1924)
authorAmos Jeffries <yadij@users.noreply.github.com>
Thu, 21 Nov 2024 10:45:23 +0000 (10:45 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Thu, 21 Nov 2024 10:45:35 +0000 (10:45 +0000)
Replacing memory allocate and destruct with C++ new/delete
and in-class initialization.

src/fs_io.cc
src/fs_io.h
src/mem/forward.h
src/mem/old_api.cc

index 78fd5b41f99f64c6d38c7bdfa638b146d6b49256..4f90b8fde72f689d7ef034590e7a998a4ede0a77 100644 (file)
@@ -364,7 +364,7 @@ diskHandleRead(int fd, void *data)
      */
 
     if (fd < 0) {
-        memFree(ctrl_dat, MEM_DREAD_CTRL);
+        delete ctrl_dat;
         return;
     }
 
@@ -414,7 +414,7 @@ diskHandleRead(int fd, void *data)
 
     cbdataReferenceDone(ctrl_dat->client_data);
 
-    memFree(ctrl_dat, MEM_DREAD_CTRL);
+    delete ctrl_dat;
 }
 
 /* start read operation */
@@ -424,16 +424,8 @@ diskHandleRead(int fd, void *data)
 void
 file_read(int fd, char *buf, int req_len, off_t offset, DRCB * handler, void *client_data)
 {
-    dread_ctrl *ctrl_dat;
     assert(fd >= 0);
-    ctrl_dat = (dread_ctrl *)memAllocate(MEM_DREAD_CTRL);
-    ctrl_dat->fd = fd;
-    ctrl_dat->offset = offset;
-    ctrl_dat->req_len = req_len;
-    ctrl_dat->buf = buf;
-    ctrl_dat->end_of_file = 0;
-    ctrl_dat->handler = handler;
-    ctrl_dat->client_data = cbdataReference(client_data);
+    const auto ctrl_dat = new dread_ctrl(fd, offset, buf, req_len, handler, cbdataReference(client_data));
     diskHandleRead(fd, ctrl_dat);
 }
 
index 05cf17acc7c33ebd221d1318a6a9b4aeb27c3c64..690817c567a27e0863e7797d1f1f2dea4bfd327e 100644 (file)
 
 class MemBuf;
 
-// POD
 class dread_ctrl
 {
+    MEMPROXY_CLASS(dread_ctrl);
 public:
-    int fd;
-    off_t offset;
-    int req_len;
-    char *buf;
-    int end_of_file;
-    DRCB *handler;
-    void *client_data;
+    dread_ctrl(int aFd, off_t aOffset, char *aBuf, int aLen, DRCB *aHandler, void *aData) :
+        fd(aFd),
+        offset(aOffset),
+        req_len(aLen),
+        buf(aBuf),
+        handler(aHandler),
+        client_data(aData)
+    {}
+    dread_ctrl(dread_ctrl &&) = delete; // no copying or moving of any kind
+    ~dread_ctrl() = default;
+
+    int fd = -1;
+    off_t offset = 0;
+    int req_len = 0;
+    char *buf = nullptr;
+    int end_of_file = 0;
+    DRCB *handler = nullptr;
+    void *client_data = nullptr;
 };
 
 class dwrite_q
index 0ec985739ee5af82e7130caece4a6b9a59691cdd..205e97014774c5cc0c6f017bee4c861fa9287b84 100644 (file)
@@ -51,7 +51,6 @@ typedef enum {
     MEM_16K_BUF,
     MEM_32K_BUF,
     MEM_64K_BUF,
-    MEM_DREAD_CTRL,
     MEM_MD5_DIGEST,
     MEM_MAX
 } mem_type;
index d6fc8058feeb335ff5aaac3bc714d6e3fc6a650b..3cbb3f38113d89586bcefccbf5a631003a533e28 100644 (file)
@@ -308,7 +308,6 @@ Mem::Init(void)
     memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10, false);
     memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10, false);
     // TODO: Carefully stop zeroing these objects memory and drop the doZero parameter
-    memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0, true);
     memDataInit(MEM_MD5_DIGEST, "MD5 digest", SQUID_MD5_DIGEST_LENGTH, 0, true);
     GetPool(MEM_MD5_DIGEST)->setChunkSize(512 * 1024);