Q:

valgrind shows memory leak even after manually freeing memory

C experts,
My main file is rchars.c as below,
#include<stdio.h>
#include<stdlib.h>
#include "lib.h"
#include "markov.h"

int main () {
  int nc;
  printf("Enter number of characters: ");
  scanf("%d", &nc);

  struct Seq *eve = malloc(sizeof(struct Seq*) - sizeof(double)); // line 11

  eve = genSeq(nc);

  for(int i=0;i<nc;i++){
    printf("acor - %d: %f\n",i, *(eve->seq+i));
  };

  free(eve->seq); // freeing the seq pointer
  free(eve); // freeing the Seq structure

return 0;   
}

Apparently I am feeing the malloc memory with free(eve->seq) and free(eve). However, valgrind analysis says 0 bytes in 1 blocks are definitely lost in loss record 1 of 1 as below:
...
...
==8783== 
==8783== HEAP SUMMARY:
==8783==     in use at exit: 0 bytes in 1 blocks
==8783==   total heap usage: 5 allocs, 4 frees, 2,084 bytes allocated
==8783== 
==8783== Searching for pointers to 1 not-freed blocks
==8783== Checked 76,336 bytes
==8783== 
==8783== 0 bytes in 1 blocks are definitely lost in loss record 1 of 1
==8783==    at 0x483977F: malloc (vg_replace_malloc.c:307)
==8783==    by 0x109870: main (rchars.c:11)
==8783== 
==8783== LEAK SUMMARY:
==8783==    definitely lost: 0 bytes in 1 blocks
==8783==    indirectly lost: 0 bytes in 0 blocks
==8783==      possibly lost: 0 bytes in 0 blocks
==8783==    still reachable: 0 bytes in 0 blocks
==8783==         suppressed: 0 bytes in 0 blocks
==8783== 
==8783== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

I am not able to figure where actually the leak happens and why even after freeing the memory as prescribed. Though what is lost is 0 bytes I am bothered with 1 block. What is that I am missing here. I am learning my way around with C. Any help/suggestion to troubleshoot and solve this would be much appreciated.
My header file has the struct Seq
...
struct Seq {
  int len;
  double *seq;
};
...

genSeq function definition is
struct Seq *genSeq(int nc) {
  int i;
  // Struct assignment
  struct Seq *data = (struct Seq *)malloc(sizeof(int) + sizeof(double)*nc);
  double *seqn = (double *)malloc(sizeof(double) * nc);
  data->len = nc;
  if (seqn) {
    srand(time(NULL));
    for(i=0;i<nc;i++){
      //*(seqn+i) = sin(i+1);
      int j = rand();
      *(seqn+i) = (double)(j % 200);
      if (j % 3 == 0) {
        *(seqn+i) = (double)1.0;
      } else if (j % 2 == 0) {
        *(seqn+i) = (double)2.0;
      } else {
        *(seqn+i) = (double)3.0;
      }; 
      //printf("Signal: %f\n", *(seqn+i));
    }
  } else {
    printf("Null pointer returned: Sequence alloc failed\n");
  }
  data->seq = seqn;

  return data;
}

I have read this valgrind shows memory leak even after memory free, but no accepted, convincing answers and doesn't help much for me.

A:

You're returning a dynamically allocated struct from within the function, so you don't need to allocate more space for it. Simply remove the memory allocation from main:
replace this: struct Seq *eve = malloc(sizeof(struct Seq*) - sizeof(double));
with struct Seq *eve = NULL;
Valgrind literally gave you the answer, by telling you that you allocated more than you should:
total heap usage: 5 allocs, 4 frees, 2,084 bytes allocated

and was kind enough to even share the exact location with you, including line number:
at 0x483977F: malloc (vg_replace_malloc.c:307)

Now, even if you wanted to allocate space for your struct in main, you did it wrong, because you allocated just enough space for struct Seq* (a pointer to struct) and not for struct Seq (a concrete struct).

