return ret;
}
+static struct ext_bininfo_t *_create_bininfo(const char *path, size_t len)
+{
+ struct ext_bininfo_t *ebi;
+
+ ebi = malloc(sizeof(*ebi));
+ if (!ebi) {
+ PRINTERR("No memory to alloc for ext_bininfo");
+ return NULL;
+ }
+
+ ebi->next = NULL;
+ ebi->path = malloc(len);
+ if (!ebi->path) {
+ PRINTERR("No memory to alloc for ext_bininfo path");
+ free(ebi);
+ return NULL;
+ }
+ memcpy(ebi->path, path, len);
+
+ return ebi;
+}
+
static void _parse_bundle(char *bundle, size_t size,
struct ext_bininfo_t **resp, parse_cb_t cb)
{
char *path;
unsigned int i;
int ret;
- struct ext_bininfo_t *res, *last, *tmp;
+ struct ext_bininfo_t *last = NULL, *tmp;
+
+ if (resp)
+ *resp = NULL;
if (!cb) {
PRINTERR("Error! No callback for parsing bundle!");
return;
}
- if (resp) {
- res = *resp;
- last = *resp;
- }
-
if (_decrease_size(&size, sizeof(cnt)))
return;
ptr += len;
ret = cb(path);
- if (!ret && resp) {
- tmp = malloc(sizeof(*tmp));
+ if (ret) {
+ PRINTERR("Adding failed, error code %d", ret);
+ } else if (resp) {
+ tmp = _create_bininfo(path, len);
if (!tmp) {
- PRINTERR("No memory to alloc for ext_bininfo");
+ free(path);
return;
}
- tmp->next = NULL;
- tmp->path = path;
- if (res) {
+
+ if (*resp) {
last->next = tmp;
last = tmp;
} else {
- res = last = tmp;
+ *resp = last = tmp;
}
- } else {
- PRINTERR("Adding failed, error code %d", ret);
}
+ free(path);
}
}