OSDN Git Service

Fixed memory leak when failing to lookup an index
authorJean-Pierre André <jpandre@users.sourceforge.net>
Sat, 11 Feb 2017 09:29:39 +0000 (10:29 +0100)
committerJean-Pierre André <jpandre@users.sourceforge.net>
Sat, 11 Feb 2017 09:29:39 +0000 (10:29 +0100)
When an index could not be used, the search context was not freed

include/ntfs-3g/index.h
libntfs-3g/index.c

index c0e7618..036b742 100644 (file)
@@ -129,6 +129,7 @@ typedef struct {
        VCN parent_vcn[MAX_PARENT_VCN]; /* entry's parent nodes */
        int pindex;          /* maximum it's the number of the parent nodes  */
        BOOL ib_dirty;
+       BOOL bad_index;
        u32 block_size;
        u8 vcn_size_bits;
 } ntfs_index_context;
index 3f7a59e..58568de 100644 (file)
@@ -143,7 +143,7 @@ static void ntfs_index_ctx_free(ntfs_index_context *icx)
 {
        ntfs_log_trace("Entering\n");
        
-       if (!icx->entry)
+       if (!icx->bad_index && !icx->entry)
                return;
 
        if (icx->actx)
@@ -719,7 +719,7 @@ int ntfs_index_lookup(const void *key, const int key_len, ntfs_index_context *ic
        ret = ntfs_ie_lookup(key, key_len, icx, &ir->index, &vcn, &ie);
        if (ret == STATUS_ERROR) {
                err = errno;
-               goto err_out;
+               goto err_lookup;
        }
        
        icx->ir = ir;
@@ -780,6 +780,8 @@ descend_into_child_node:
        
        goto descend_into_child_node;
 err_out:
+       icx->bad_index = TRUE;  /* Force icx->* to be freed */
+err_lookup:
        free(ib);
        if (!err)
                err = EIO;