diff options
author | Karel Zak | 2014-03-19 16:29:39 +0100 |
---|---|---|
committer | Karel Zak | 2014-04-03 12:29:16 +0200 |
commit | c638c57ac3af8b819ef7b71804d585c3e9cf549c (patch) | |
tree | 8c3c06a279c2cf91285b3dd4ef9fb3f19a2a8307 /libsmartcols/src/symbols.c | |
parent | include/carefulputc: cleanup and add fputs_{quoted,nonblank}() (diff) | |
download | kernel-qcow2-util-linux-c638c57ac3af8b819ef7b71804d585c3e9cf549c.tar.gz kernel-qcow2-util-linux-c638c57ac3af8b819ef7b71804d585c3e9cf549c.tar.xz kernel-qcow2-util-linux-c638c57ac3af8b819ef7b71804d585c3e9cf549c.zip |
libsmartcols: add table struct, cleanup refcounting
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/src/symbols.c')
-rw-r--r-- | libsmartcols/src/symbols.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/libsmartcols/src/symbols.c b/libsmartcols/src/symbols.c index 344ddcf53..7f5f56f7a 100644 --- a/libsmartcols/src/symbols.c +++ b/libsmartcols/src/symbols.c @@ -7,9 +7,32 @@ struct libscols_symbols *scols_new_symbols(void) { - return calloc(1, sizeof(struct libscols_symbols)); + struct libscols_symbols *sy = calloc(1, sizeof(struct libscols_symbols)); + + if (!sy) + return NULL; + sy->refcount = 1; + return sy; } + +void scols_ref_symbols(struct libscols_symbols *sy) +{ + if (sy) + sy->refcount++; +} + +void scols_unref_symbols(struct libscols_symbols *sy) +{ + if (sy && --sy->refcount <= 0) { + free(sy->branch); + free(sy->vert); + free(sy->right); + free(sy); + } +} + + int scols_symbols_set_branch(struct libscols_symbols *sb, const char *str) { char *p = NULL; @@ -86,18 +109,9 @@ struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sb) if (!rc) return ret; - scols_free_symbols(ret); + scols_unref_symbols(ret); return NULL; } -void scols_free_symbols(struct libscols_symbols *sb) -{ - if (!sb) - return; - free(sb->branch); - free(sb->vert); - free(sb->right); - free(sb); -} |