return 0;
}
+static void pakfire_linter_file_free(struct pakfire_linter_file* lfile) {
+ int r;
+
+ if (lfile->elf)
+ pakfire_elf_unref(lfile->elf);
+
+ if (lfile->data) {
+ r = munmap(lfile->data, lfile->length);
+ if (r < 0)
+ ERROR(lfile->ctx, "Could not unmmap %s: %m\n", lfile->path);
+ }
+
+ if (lfile->fd >= 0)
+ close(lfile->fd);
+
+ if (lfile->linter)
+ pakfire_linter_unref(lfile->linter);
+ if (lfile->file)
+ pakfire_file_unref(lfile->file);
+ if (lfile->ctx)
+ pakfire_ctx_unref(lfile->ctx);
+ free(lfile);
+}
+
int pakfire_linter_file_create(struct pakfire_linter_file** lfile,
struct pakfire_ctx* ctx, struct pakfire_linter* linter, struct pakfire_file* file, int fd) {
struct pakfire_linter_file* l = NULL;
}
// Return the pointer
- *lfile = pakfire_linter_file_ref(l);
+ *lfile = l;
+ return 0;
ERROR:
- if (l)
- pakfire_linter_file_unref(l);
+ pakfire_linter_file_free(l);
return r;
}
-static void pakfire_linter_file_free(struct pakfire_linter_file* lfile) {
- int r;
-
- if (lfile->elf)
- pakfire_elf_unref(lfile->elf);
-
- if (lfile->data) {
- r = munmap(lfile->data, lfile->length);
- if (r < 0)
- ERROR(lfile->ctx, "Could not unmmap %s: %m\n", lfile->path);
- }
-
- if (lfile->fd >= 0)
- close(lfile->fd);
-
- if (lfile->linter)
- pakfire_linter_unref(lfile->linter);
- if (lfile->file)
- pakfire_file_unref(lfile->file);
- if (lfile->ctx)
- pakfire_ctx_unref(lfile->ctx);
- free(lfile);
-}
struct pakfire_linter_file* pakfire_linter_file_ref(struct pakfire_linter_file* lfile) {
++lfile->nrefs;