Browse Source

[core] mark attr malloc, returns nonnull

mark some core code with attributes malloc, returns nonnull
master
Glenn Strauss 1 month ago
parent
commit
b38817b678
  1. 1
      src/buffer.h
  2. 7
      src/fdevent.c
  3. 1
      src/fdlog.h
  4. 6
      src/gw_backend.c
  5. 2
      src/plugin.c
  6. 1
      src/server.c
  7. 3
      src/stat_cache.c

1
src/buffer.h

@ -29,6 +29,7 @@ typedef struct {
} buffer;
/* create new buffer; either empty or copy given data */
__attribute_malloc__
__attribute_returns_nonnull__
buffer* buffer_init(void);

7
src/fdevent.c

@ -281,8 +281,12 @@ int fdevent_reset(fdevents *ev) {
return rc;
}
__attribute_malloc__
__attribute_returns_nonnull__
static fdnode *fdnode_init(void) {
return calloc(1, sizeof(fdnode));
fdnode * const restrict fdn = calloc(1, sizeof(fdnode));
force_assert(NULL != fdn);
return fdn;
}
static void fdnode_free(fdnode *fdn) {
@ -291,7 +295,6 @@ static void fdnode_free(fdnode *fdn) {
fdnode * fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx) {
fdnode *fdn = ev->fdarray[fd] = fdnode_init();
force_assert(NULL != fdn);
fdn->handler = handler;
fdn->fd = fd;
fdn->ctx = ctx;

1
src/fdlog.h

@ -13,7 +13,6 @@ typedef struct fdlog_st {
} fdlog_st;
__attribute_cold__
__attribute_malloc__
__attribute_returns_nonnull__
fdlog_st * fdlog_init (const char *fn, int fd, int mode);

6
src/gw_backend.c

@ -158,6 +158,7 @@ static void gw_proc_init_portpath(gw_host *host, gw_proc *proc) {
__attribute_cold__
__attribute_noinline__
__attribute_returns_nonnull__
static gw_proc *gw_proc_init(gw_host *host) {
gw_proc *proc = calloc(1, sizeof(*proc));
force_assert(proc);
@ -188,6 +189,8 @@ static void gw_proc_free(gw_proc *proc) {
free(proc);
}
__attribute_malloc__
__attribute_returns_nonnull__
static gw_host *gw_host_init(void) {
gw_host *f = calloc(1, sizeof(*f));
force_assert(f);
@ -209,6 +212,8 @@ static void gw_host_free(gw_host *h) {
free(h);
}
__attribute_malloc__
__attribute_returns_nonnull__
static gw_exts *gw_extensions_init(void) {
gw_exts *f = calloc(1, sizeof(*f));
force_assert(f);
@ -1108,6 +1113,7 @@ static void gw_restart_dead_procs(gw_host * const host, log_error_st * const err
static handler_t gw_handle_fdevent(void *ctx, int revents);
__attribute_returns_nonnull__
static gw_handler_ctx * handler_ctx_init(size_t sz) {
gw_handler_ctx *hctx = calloc(1, 0 == sz ? sizeof(*hctx) : sz);
force_assert(hctx);

2
src/plugin.c

@ -53,6 +53,8 @@ typedef enum {
PLUGIN_FUNC_SIZEOF
} plugin_t;
__attribute_malloc__
__attribute_returns_nonnull__
static plugin *plugin_init(void) {
plugin *p;

1
src/server.c

@ -274,6 +274,7 @@ server_epoch_secs (server * const srv)
__attribute_cold__
__attribute_noinline__
__attribute_returns_nonnull__
static server *server_init(void) {
server *srv = calloc(1, sizeof(*srv));
force_assert(srv);

3
src/stat_cache.c

@ -237,6 +237,7 @@ typedef struct stat_cache_fam {
int fd;
} stat_cache_fam;
__attribute_returns_nonnull__
static fam_dir_entry * fam_dir_entry_init(const char *name, size_t len)
{
fam_dir_entry * const fam_dir = calloc(1, sizeof(*fam_dir));
@ -789,6 +790,8 @@ static fam_dir_entry * fam_dir_monitor(stat_cache_fam *scf, char *fn, uint32_t d
#endif
__attribute_malloc__
__attribute_returns_nonnull__
static stat_cache_entry * stat_cache_entry_init(void) {
stat_cache_entry *sce = calloc(1, sizeof(*sce));
force_assert(NULL != sce);

Loading…
Cancel
Save