pm

barely a pack manager
git clone git://z3bra.org/pm
Log | Files | Refs | README | LICENSE

commit cdc9e1e65dc1b8a5d90ea60d708e81f599c0f2bf
parent e6ba7b3f0f832855bd1ea7323644fcf0c9d39258
Author: z3bra <willyatmailoodotorg>
Date:   Tue Jan 12 12:24:57 2016

Free pack structs failing to load

Diffstat:
 pm.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/pm.c b/pm.c @@ -524,13 +524,21 @@ pack_load(char *path) } close(fd); - pack = malloc(sizeof(struct pack)); + if (!(pack = malloc(sizeof(struct pack)))) { + perror(path); + return NULL; + } + + pack->path = NULL; + pack->name = NULL; + pack->version = NULL; + pack->path = strdup(path); snprintf(tmp, PATH_MAX, "%s", base_name(path)); for (p = tmp; *p && *p != ':'; p++); if (!*p) { - free(pack); + pack_free(pack); return NULL; } *p = 0; @@ -540,7 +548,7 @@ pack_load(char *path) snprintf(tmp, PATH_MAX, "%s", p + 1); for (p = tmp; *p && strcmp(p, PACK_EXTENSION); p++); if (!*p) { - free(pack); + pack_free(pack); return NULL; } *p = 0; @@ -560,9 +568,13 @@ pack_free(struct pack *p) if (!p) return; - free(p->path); - free(p->name); - free(p->version); + if (p->path) + free(p->path); + if (p->name) + free(p->name); + if (p->version) + free(p->version); + free(p); }