mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-16 05:24:20 +02:00
Ensure usage of __attribute__(cleanup) never frees un-initialized memory
Use macros that take an initializer parameter to, thereby ensuring the variable to be cleaned up is always initialized.
This commit is contained in:
@@ -46,10 +46,10 @@
|
||||
void log_error(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
#define fatal(...) { log_error(__VA_ARGS__); exit(EXIT_FAILURE); }
|
||||
static inline void cleanup_free(void *p) { free(*(void**)p); }
|
||||
#define FREE_AFTER_FUNCTION __attribute__((cleanup(cleanup_free)))
|
||||
#define RAII_ALLOC(type, name, initializer) __attribute__((cleanup(cleanup_free))) type *name = initializer
|
||||
static inline void cleanup_decref(PyObject **p) { if(*p) { Py_DECREF(*p); *p = NULL;} }
|
||||
#define DECREF_AFTER_FUNCTION __attribute__((cleanup(cleanup_decref)))
|
||||
#define FREE_BUFFER_AFTER_FUNCTION __attribute__((cleanup(PyBuffer_Release)))
|
||||
#define RAII_PyObject(name, initializer) __attribute__((cleanup(cleanup_decref))) PyObject *name = initializer
|
||||
#define RAII_PY_BUFFER(name) __attribute__((cleanup(PyBuffer_Release))) Py_buffer name = {0}
|
||||
|
||||
typedef unsigned long long id_type;
|
||||
typedef uint32_t char_type;
|
||||
|
||||
Reference in New Issue
Block a user