R
Ramon
I have a pointer (result) of type void, which is passed (via parameter)
to another function named preocessResult().
At processResult() a pointer of type int (res) is malloced and data is
stored in the allocated space. res is type-casted to void * and
returned as result.
Everything seems to be ok, but when I run valgrind it gives the
following warnings:
==3186== Invalid read of size 1
==3186== at 0x401EB8C: memcpy (mc_replace_strmem.c:406)
==3186== by 0x804844A: foo (test.c:43)
==3186== by 0x8048462: main (test.c:54)
==3186== Address 0x416408B is not stack'd, malloc'd or (recently) free'd
==3186==
==3186== Invalid read of size 1
==3186== at 0x401EB91: memcpy (mc_replace_strmem.c:406)
==3186== by 0x804844A: foo (test.c:43)
==3186== by 0x8048462: main (test.c:54)
==3186== Address 0x416408A is not stack'd, malloc'd or (recently) free'd
==3186==
==3186== Invalid read of size 1
==3186== at 0x401EB98: memcpy (mc_replace_strmem.c:406)
==3186== by 0x804844A: foo (test.c:43)
==3186== by 0x8048462: main (test.c:54)
==3186== Address 0x4164089 is not stack'd, malloc'd or (recently) free'd
==3186==
==3186== Invalid read of size 1
==3186== at 0x401EB9F: memcpy (mc_replace_strmem.c:406)
==3186== by 0x804844A: foo (test.c:43)
==3186== by 0x8048462: main (test.c:54)
==3186== Address 0x4164088 is not stack'd, malloc'd or (recently) free'd
Can any one figures out where is the mistake(s) please?
Here is my code:
void processResult(void **result)
{
int *res = (int *) malloc(sizeof(int));
*res = 505;
*result = res;
}
void foo()
{
void *result = NULL;
struct mytask mtask;
processResult(&result);
if (result == NULL)
bzero( &mtask, sizeof(struct mytask) );
else
mtask = *((struct mytask *) result);
}
to another function named preocessResult().
At processResult() a pointer of type int (res) is malloced and data is
stored in the allocated space. res is type-casted to void * and
returned as result.
Everything seems to be ok, but when I run valgrind it gives the
following warnings:
==3186== Invalid read of size 1
==3186== at 0x401EB8C: memcpy (mc_replace_strmem.c:406)
==3186== by 0x804844A: foo (test.c:43)
==3186== by 0x8048462: main (test.c:54)
==3186== Address 0x416408B is not stack'd, malloc'd or (recently) free'd
==3186==
==3186== Invalid read of size 1
==3186== at 0x401EB91: memcpy (mc_replace_strmem.c:406)
==3186== by 0x804844A: foo (test.c:43)
==3186== by 0x8048462: main (test.c:54)
==3186== Address 0x416408A is not stack'd, malloc'd or (recently) free'd
==3186==
==3186== Invalid read of size 1
==3186== at 0x401EB98: memcpy (mc_replace_strmem.c:406)
==3186== by 0x804844A: foo (test.c:43)
==3186== by 0x8048462: main (test.c:54)
==3186== Address 0x4164089 is not stack'd, malloc'd or (recently) free'd
==3186==
==3186== Invalid read of size 1
==3186== at 0x401EB9F: memcpy (mc_replace_strmem.c:406)
==3186== by 0x804844A: foo (test.c:43)
==3186== by 0x8048462: main (test.c:54)
==3186== Address 0x4164088 is not stack'd, malloc'd or (recently) free'd
Can any one figures out where is the mistake(s) please?
Here is my code:
void processResult(void **result)
{
int *res = (int *) malloc(sizeof(int));
*res = 505;
*result = res;
}
void foo()
{
void *result = NULL;
struct mytask mtask;
processResult(&result);
if (result == NULL)
bzero( &mtask, sizeof(struct mytask) );
else
mtask = *((struct mytask *) result);
}