@@ -91,15 +91,14 @@ open_cache_file(const char *cache_path) {
9191 }
9292#else
9393 size_t sz = strlen (cache_path ) + 16 ;
94- char * buf = calloc (1 , sz );
94+ FREE_AFTER_FUNCTION char * buf = calloc (1 , sz );
9595 if (!buf ) { errno = ENOMEM ; return -1 ; }
9696 snprintf (buf , sz - 1 , "%s/disk-cache-XXXXXXXXXXXX" , cache_path );
9797 while (fd < 0 ) {
9898 fd = mkostemp (buf , O_CLOEXEC );
9999 if (fd > -1 || errno != EINTR ) break ;
100100 }
101101 if (fd > -1 ) unlink (buf );
102- free (buf );
103102#endif
104103 return fd ;
105104}
@@ -171,8 +170,8 @@ typedef struct {
171170static void
172171defrag (DiskCache * self ) {
173172 int new_cache_file = -1 ;
174- DefragEntry * defrag_entries = NULL ;
175- uint8_t * buf = NULL ;
173+ FREE_AFTER_FUNCTION DefragEntry * defrag_entries = NULL ;
174+ FREE_AFTER_FUNCTION uint8_t * buf = NULL ;
176175 const size_t bufsz = 1024 * 1024 ;
177176 bool lock_released = false, ok = false;
178177
@@ -235,8 +234,6 @@ defrag(DiskCache *self) {
235234 if (s ) s -> pos_in_cache_file = e -> new_offset ;
236235 }
237236 }
238- if (defrag_entries ) free (defrag_entries );
239- if (buf ) free (buf );
240237 if (new_cache_file > -1 ) safe_close (new_cache_file , __FILE__ , __LINE__ );
241238}
242239
@@ -484,7 +481,7 @@ add_to_disk_cache(PyObject *self_, const void *key, size_t key_sz, const void *d
484481 if (!ensure_state (self )) return false;
485482 if (key_sz > MAX_KEY_SIZE ) { PyErr_SetString (PyExc_KeyError , "cache key is too long" ); return false; }
486483 CacheEntry * s = NULL ;
487- uint8_t * copied_data = malloc (data_sz );
484+ FREE_AFTER_FUNCTION uint8_t * copied_data = malloc (data_sz );
488485 if (!copied_data ) { PyErr_NoMemory (); return false; }
489486 memcpy (copied_data , data , data_sz );
490487
@@ -503,8 +500,6 @@ add_to_disk_cache(PyObject *self_, const void *key, size_t key_sz, const void *d
503500 self -> total_size += s -> data_sz ;
504501end :
505502 mutex (unlock );
506-
507- if (copied_data ) free (copied_data );
508503 if (PyErr_Occurred ()) return false;
509504 wakeup_write_loop (self );
510505 return true;
0 commit comments