| 19759 | } |
| 19760 | |
| 19761 | void gguf_free(struct gguf_context * ctx) { |
| 19762 | if (ctx == NULL) { |
| 19763 | return; |
| 19764 | } |
| 19765 | |
| 19766 | if (ctx->kv) { |
| 19767 | // free string memory - not great.. |
| 19768 | for (uint32_t i = 0; i < ctx->header.n_kv; ++i) { |
| 19769 | struct gguf_kv * kv = &ctx->kv[i]; |
| 19770 | |
| 19771 | if (kv->key.data) { |
| 19772 | free(kv->key.data); |
| 19773 | } |
| 19774 | |
| 19775 | if (kv->type == GGUF_TYPE_STRING) { |
| 19776 | if (kv->value.str.data) { |
| 19777 | free(kv->value.str.data); |
| 19778 | } |
| 19779 | } |
| 19780 | |
| 19781 | if (kv->type == GGUF_TYPE_ARRAY) { |
| 19782 | if (kv->value.arr.data) { |
| 19783 | if (kv->value.arr.type == GGUF_TYPE_STRING) { |
| 19784 | for (uint32_t j = 0; j < kv->value.arr.n; ++j) { |
| 19785 | struct gguf_str * str = &((struct gguf_str *) kv->value.arr.data)[j]; |
| 19786 | if (str->data) { |
| 19787 | free(str->data); |
| 19788 | } |
| 19789 | } |
| 19790 | } |
| 19791 | free(kv->value.arr.data); |
| 19792 | } |
| 19793 | } |
| 19794 | } |
| 19795 | |
| 19796 | free(ctx->kv); |
| 19797 | } |
| 19798 | |
| 19799 | if (ctx->infos) { |
| 19800 | for (uint32_t i = 0; i < ctx->header.n_tensors; ++i) { |
| 19801 | struct gguf_tensor_info * info = &ctx->infos[i]; |
| 19802 | |
| 19803 | if (info->name.data) { |
| 19804 | free(info->name.data); |
| 19805 | } |
| 19806 | } |
| 19807 | |
| 19808 | free(ctx->infos); |
| 19809 | } |
| 19810 | |
| 19811 | GGML_ALIGNED_FREE(ctx); |
| 19812 | } |
| 19813 | |
| 19814 | const char * gguf_type_name(enum gguf_type type) { |
| 19815 | return GGUF_TYPE_NAME[type]; |
no outgoing calls
no test coverage detected