I notice something below as well. Below are some observations main()->load_core_resident_fs_data()->get_tpf_rw() called suppose 1236 times in loop and get_tpf_rw() calls SQL_get_tpf_rw() and inside SQL_get_tpf_rw, if you see at last few lines (full definition shared in other attachment fun_def_and_other_details.txt) int SQL_get_tpf_rw( int32_t fa, unsigned char **core_blk, size_t *st_size, unsigned char *bid, unsigned char *rcc, int *fd, bool hold, unsigned char **mmap_ptr) { char *p; char *c; int rc; PGresult *res; .... ... //Please see here *fd = fa; // use File Address as File Descriptor c = PQgetvalue(res, 0, 1); // SELECT has data as second field //dump_hex(c,16); //printf(" PQgetlength of data = %i\n",PQgetlength(res,0,1)); p = c; // use same pointer for both mmap and core_blk //LOG_DEBUG("Core block address %p for FA %08X (RW)", p, fa); //dump_hex(p,32); /* probably need some validation of block size? */ if (bid != NULL && memcmp(bid, p, 2) != 0 && memcmp(bid, "\x00\x00", 2) != 0) { rc = ERR_RID_MISMATCH; int b1 = *(unsigned char *)p; int b2 = *(unsigned char *)(p+1); int a1 = *(unsigned char *)(bid); int a2 = *(unsigned char *)(bid+1); LOG_ERROR("Error record id mismatch %02X%02X != %02X%02X FA %08X", b1, b2, a1, a2, fa); } else if (rcc != NULL && *rcc != 0 && memcmp(rcc, p+2, 1) != 0) { rc = ERR_RCC_MISMATCH; int b1 = *(unsigned char *)(p+2); int a1 = *(unsigned char *)(rcc); LOG_ERROR("Error rcc mismatch %02X != %02X FA %08X", b1, a1, fa); } else { rc = 0; } *mmap_ptr = c; *core_blk = p; *st_size = blk_size; //dump_hex(*mmap_ptr,1055); } and once after every call is made SQL_get_tpf_rw(), in load_core_resident_fs_data() we then call release_tpf() and FREEC() whose definition is given below my doubt is we are doing FILE_release_tpf() and FREEC() in case of file_path/sql_db = false(data comes from file). how can we avoid mem leaks reported in case of PGresult created when sql_db=true (and it means the data comes from PostgreSQL). ***How do we handle for the case clearing when PGresult object is assigned a pointer to the data of the specified field within the existing PGresult object? i.e when SQL_get_tpf_rw() actually completes in each iteration? ****Is the leak reported due to improper handling of the above case ? or is it due to some other flow c = PQgetvalue(res, 0, 1); // SELECT has data as second field //Below are some more functions definitions int get_tpf_rw( int32_t fa, unsigned char **core_blk, size_t *st_size, unsigned char *bid, unsigned char *rcc, int *fd, bool hold, unsigned char * *mmap_ptr) { if(sql_db == 1)// { return SQL_get_tpf_rw(fa, core_blk, st_size, bid, rcc, fd, hold, mmap_ptr ); // } else //if(sql_db == 0) return FILE_get_tpf_rw(fa, core_blk, st_size, bid, rcc, fd, hold, mmap_ptr ); } void FILE_release_tpf(int32_t fd, unsigned char *mmap_ptr, size_t st_size) { LOG_TRACE("%s() - fd = %i mmap = %p st_size = %i ------------",__func__,fd,mmap_ptr,(int)st_size); munmap(mmap_ptr, st_size); } void release_tpf(int32_t fd, unsigned char *mmap_ptr, size_t st_size) { LOG_TRACE("%s() - fd = %i mmap = %p st_size = %i ------------",__func__,fd,mmap_ptr,(int)st_size); if(!sql_db) { FILE_release_tpf(fd, mmap_ptr, st_size); } } void FREEC( int32_t block) { LOG_TRACE("%s() block %08x ----------------------------------",__func__,block); if(!sql_db) free( (void *)block ); }