Be aware that the size of basic types like int or long is not fixed in C/C++, but is platform-specific.
A single int may be 4 bytes (32-Bit) in size on most platforms today, but could also be 8 bytes (64-Bit) or maybe only 2 bytes (16-Bit). The malloc() function is rather "dumb" and simply allocates whichever number of bytes that you asked for. Consequently, in order to write portable code, you better use the sizeof() operator to determine the actual size of a the data type that you intend to allocate - instead of making assumptions about its size!
Either that, or, if you are programming in C++, use the new operator:
int *ptr = newint; // <-- similar to "(int*)malloc(sizeof(int))"
int *array = newint; // <-- similar to "(int*)malloc(42 * sizeof(int))"
If memory was allocated by new or new, then you have to use delete or delete instead of free() to free it!