mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-07 10:48:07 +02:00
Merge branch 'wip/clear-pointer' into 'main'
util: add a free_clear() helper to reset after free See merge request libinput/libinput!1472
This commit is contained in:
commit
ddce92d177
5 changed files with 16 additions and 8 deletions
|
|
@ -375,8 +375,7 @@ remove_device(struct libinput_lua_plugin *plugin, EvdevDevice *evdev)
|
|||
list_for_each_safe(prop, &evdev->udev_properties_list, link) {
|
||||
udev_property_destroy(prop);
|
||||
}
|
||||
free(evdev->name);
|
||||
evdev->name = NULL;
|
||||
free_clear(&evdev->name);
|
||||
evdev->device = libinput_device_unref(evdev->device);
|
||||
|
||||
/* This device no longer exists but our lua code may have a
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "util-macros.h"
|
||||
#include "util-mem.h"
|
||||
|
||||
#define bit(x_) (1UL << (x_))
|
||||
#define NBITS(b) (b * 8)
|
||||
|
|
@ -281,8 +282,7 @@ infmask_new(void)
|
|||
|
||||
_nonnull_(1) static inline void infmask_reset(infmask_t *mask)
|
||||
{
|
||||
free(mask->mask);
|
||||
mask->mask = NULL;
|
||||
free_clear(&mask->mask);
|
||||
mask->nmasks = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -186,3 +186,14 @@ steal_fd(int *fd)
|
|||
*fd = -1;
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the pointer content and resets the data to NULL.
|
||||
*/
|
||||
#define free_clear(ptr_) \
|
||||
do { \
|
||||
typeof((ptr_)) _pp = (ptr_); \
|
||||
typeof(*(ptr_)) _p = *_pp; \
|
||||
*_pp = NULL; \
|
||||
free(_p); \
|
||||
} while(0)
|
||||
|
|
|
|||
|
|
@ -53,8 +53,7 @@ stringbuf_is_empty(struct stringbuf *b)
|
|||
static inline void
|
||||
stringbuf_reset(struct stringbuf *b)
|
||||
{
|
||||
free(b->data);
|
||||
b->data = NULL;
|
||||
free_clear(&b->data);
|
||||
b->sz = 0;
|
||||
b->len = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2372,8 +2372,7 @@ mainloop(struct record_context *ctx)
|
|||
}
|
||||
}
|
||||
}
|
||||
free(ctx->output_file.name_with_suffix);
|
||||
ctx->output_file.name_with_suffix = NULL;
|
||||
free_clear(&ctx->output_file.name_with_suffix);
|
||||
} while (autorestart && !ctx->stop);
|
||||
|
||||
sigprocmask(SIG_UNBLOCK, &mask, NULL);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue