blobstore: don't realloc any memory under scan-build
Scan-build has a real issue with reallocs. The original error from latest version of scan-build is rather complicated, but it can be greatly simplified with the following change: > diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c > index 7580c9dd2..6a594edf3 100644 > --- a/lib/blob/blobstore.c > +++ b/lib/blob/blobstore.c > @@ -1147,8 +1147,9 @@ > _spdk_blob_persist_clear_clusters_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int > } else if (blob->active.num_clusters != blob->active.cluster_array_size) { > tmp = realloc(blob->active.clusters, sizeof(uint64_t) * blob->active.num_clusters); > assert(tmp != NULL); > - blob->active.clusters = tmp; > - blob->active.cluster_array_size = blob->active.num_clusters; > + ctx->blob->active.clusters = tmp; > + assert(ctx->blob->active.clusters[0] != 14213); > + ctx->blob->active.cluster_array_size = ctx->blob->active.num_clusters; > } > > _spdk_blob_persist_complete(seq, ctx, bserrno); > ``` Scan-build will then complain: blobstore.c:1151:10: warning: Use of memory after it is freed assert(ctx->blob->active.clusters[0] != 14213); Asserting blob == ctx->blob, blob->active.clusters == ctx->..., or even tmp != blob->active.clusters doesn't work, so use the last resort scan-build weapon - #ifdef __clang_analyzer__. The realloc in this case is just down-sizing a buffer to save some memory. For scan-build, just don't do it. This finally silences all scan-build false positives. Change-Id: Ib88ea145370f5035eedd2412e98ee61f96ad1915 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/462868 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
5282edfd7b
commit
bb63fe6fc3
@ -1127,7 +1127,6 @@ _spdk_blob_persist_clear_clusters_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int
|
|||||||
struct spdk_blob_persist_ctx *ctx = cb_arg;
|
struct spdk_blob_persist_ctx *ctx = cb_arg;
|
||||||
struct spdk_blob *blob = ctx->blob;
|
struct spdk_blob *blob = ctx->blob;
|
||||||
struct spdk_blob_store *bs = blob->bs;
|
struct spdk_blob_store *bs = blob->bs;
|
||||||
void *tmp;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* Release all clusters that were truncated */
|
/* Release all clusters that were truncated */
|
||||||
@ -1145,9 +1144,14 @@ _spdk_blob_persist_clear_clusters_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int
|
|||||||
blob->active.clusters = NULL;
|
blob->active.clusters = NULL;
|
||||||
blob->active.cluster_array_size = 0;
|
blob->active.cluster_array_size = 0;
|
||||||
} else if (blob->active.num_clusters != blob->active.cluster_array_size) {
|
} else if (blob->active.num_clusters != blob->active.cluster_array_size) {
|
||||||
|
#ifndef __clang_analyzer__
|
||||||
|
void *tmp;
|
||||||
|
|
||||||
|
/* scan-build really can't figure reallocs, workaround it */
|
||||||
tmp = realloc(blob->active.clusters, sizeof(uint64_t) * blob->active.num_clusters);
|
tmp = realloc(blob->active.clusters, sizeof(uint64_t) * blob->active.num_clusters);
|
||||||
assert(tmp != NULL);
|
assert(tmp != NULL);
|
||||||
blob->active.clusters = tmp;
|
blob->active.clusters = tmp;
|
||||||
|
#endif
|
||||||
blob->active.cluster_array_size = blob->active.num_clusters;
|
blob->active.cluster_array_size = blob->active.num_clusters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user