diff options
author | Vasilii Chernov <vchernov@inr.ru> | 2016-02-24 18:24:22 +0100 |
---|---|---|
committer | Vasilii Chernov <vchernov@inr.ru> | 2016-02-24 18:24:22 +0100 |
commit | b0a034e6ef4a958235a56ebde0831c0f30a84d30 (patch) | |
tree | a1f46d2d536c692edd6b17efc61ac9fefef2796b /pcilib/view.c | |
parent | da842568b94b0e00c1709ae01f441a7424c15b87 (diff) | |
parent | 3ea1907f3169e0233d3a32a7d470af3c34b6f967 (diff) | |
download | pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.tar.gz pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.tar.bz2 pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.tar.xz pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.zip |
Merge with Suren branch. Fix memory leaks.
Diffstat (limited to 'pcilib/view.c')
-rw-r--r-- | pcilib/view.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/pcilib/view.c b/pcilib/view.c index 797f4ae..985c1b2 100644 --- a/pcilib/view.c +++ b/pcilib/view.c @@ -69,8 +69,11 @@ int pcilib_add_views_custom(pcilib_t *ctx, size_t n, const pcilib_view_descripti return PCILIB_ERROR_MEMORY; } + memcpy(cur, v, v->api->description_size); + ctx->views[ctx->num_views + i] = cur; + if (v->api->init) - view_ctx = v->api->init(ctx, v); + view_ctx = v->api->init(ctx, ctx->num_views + i); else { view_ctx = (pcilib_view_context_t*)malloc(sizeof(pcilib_view_context_t)); if (view_ctx) memset(view_ctx, 0, sizeof(pcilib_view_context_t)); @@ -83,14 +86,12 @@ int pcilib_add_views_custom(pcilib_t *ctx, size_t n, const pcilib_view_descripti return PCILIB_ERROR_FAILED; } - memcpy(cur, v, v->api->description_size); - view_ctx->view = ctx->num_views + i; + view_ctx->view = ctx->num_views + i; view_ctx->name = v->name; - if (refs) refs[i] = view_ctx; - HASH_ADD_KEYPTR(hh, ctx->view_hash, view_ctx->name, strlen(view_ctx->name), view_ctx); - ctx->views[ctx->num_views + i] = cur; + + if (refs) refs[i] = view_ctx; ptr += v->api->description_size; } |