Browse Source

Use tor_malloc / tor_free instead of malloc / free

Ian Goldberg 3 years ago
parent
commit
cd8dba2b45
1 changed files with 5 additions and 7 deletions
  1. 5 7
      src/feature/hs/hs_cache.c

+ 5 - 7
src/feature/hs/hs_cache.c

@@ -1027,10 +1027,9 @@ hs_cache_pirserver_stdoutcb(evutil_socket_t fd, short what,
         readleft -= res;
         if (readleft == 0) {
             readleft = ntohl(*(uint32_t*)(hdrbuf+PIRSERVER_HDR_SIZE-4));
-            free(bodybuf);
-            bodybuf = NULL;
+            tor_free(bodybuf);
             if (readleft > 0) {
-                bodybuf = malloc(readleft);
+                bodybuf = tor_malloc(readleft);
                 readoff = 0;
                 readstate = PIRSERVER_READSTATE_BODY;
             } else {
@@ -1050,8 +1049,7 @@ hs_cache_pirserver_stdoutcb(evutil_socket_t fd, short what,
             hs_cache_pirserver_received(hdrbuf, bodybuf, readoff);
 
             /* Prepare for the next output from the PIR server */
-            free(bodybuf);
-            bodybuf = NULL;
+            tor_free(bodybuf);
             readoff = 0;
             readleft = PIRSERVER_HDR_SIZE;
             readstate = PIRSERVER_READSTATE_HEADER;
@@ -1078,7 +1076,7 @@ hs_cache_pirserver_stdincb(evutil_socket_t fd, short what,
         return;
     }
 
-    netbuf = malloc(bufsize);
+    netbuf = tor_malloc(bufsize);
     if (netbuf == NULL) {
         log_err(LD_DIRSERV,"PIRSERVER failed to allocate buffer");
         return;
@@ -1090,7 +1088,7 @@ hs_cache_pirserver_stdincb(evutil_socket_t fd, short what,
      * more manually.  Using a bufferevent may be another option. */
     buf_peek(pirserver_stdin_buf, netbuf, bufsize);
     res = write(fd, netbuf, bufsize);
-    free(netbuf);
+    tor_free(netbuf);
     if (res < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
         /* Try writing again later */
         event_add(pirserver_stdin_ev, NULL);