mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-04 16:31:17 -05:00
Fixed numerous memory leaks in wsprd with the help of valgrind..
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@8492 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
8d7b9bba56
commit
0eb941e082
@ -74,7 +74,7 @@ unsigned long readc2file(char *ptr_to_infile, float *idat, float *qdat,
|
|||||||
FILE* fp;
|
FILE* fp;
|
||||||
|
|
||||||
buffer=malloc(sizeof(float)*2*65536);
|
buffer=malloc(sizeof(float)*2*65536);
|
||||||
memset(buffer,0,sizeof(float)*2*65536);
|
for (i=0; i<2*65536; i++) buffer[i]=0.0;
|
||||||
|
|
||||||
fp = fopen(ptr_to_infile,"rb");
|
fp = fopen(ptr_to_infile,"rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
@ -548,12 +548,14 @@ void subtract_signal2(float *id, float *qd, long np,
|
|||||||
cfi=malloc(sizeof(float)*nc2);
|
cfi=malloc(sizeof(float)*nc2);
|
||||||
cfq=malloc(sizeof(float)*nc2);
|
cfq=malloc(sizeof(float)*nc2);
|
||||||
|
|
||||||
memset(refi,0,sizeof(float)*nc2);
|
for (i=0; i<nc2; i++) {
|
||||||
memset(refq,0,sizeof(float)*nc2);
|
refi[i]=0.0;
|
||||||
memset(ci,0,sizeof(float)*nc2);
|
refq[i]=0.0;
|
||||||
memset(cq,0,sizeof(float)*nc2);
|
ci[i]=0.0;
|
||||||
memset(cfi,0,sizeof(float)*nc2);
|
cq[i]=0.0;
|
||||||
memset(cfq,0,sizeof(float)*nc2);
|
cfi[i]=0.0;
|
||||||
|
cfq[i]=0.0;
|
||||||
|
}
|
||||||
|
|
||||||
twopidt=2.0*pi*dt;
|
twopidt=2.0*pi*dt;
|
||||||
|
|
||||||
@ -600,7 +602,7 @@ void subtract_signal2(float *id, float *qd, long np,
|
|||||||
|
|
||||||
//lowpass filter and remove startup transient
|
//lowpass filter and remove startup transient
|
||||||
float w[nfilt], norm=0, partialsum[nfilt];
|
float w[nfilt], norm=0, partialsum[nfilt];
|
||||||
memset(partialsum,0,sizeof(float)*nfilt);
|
for (i=0; i<nfilt; i++) partialsum[i]=0.0;
|
||||||
for (i=0; i<nfilt; i++) {
|
for (i=0; i<nfilt; i++) {
|
||||||
w[i]=sin(pi*(float)i/(float)(nfilt-1));
|
w[i]=sin(pi*(float)i/(float)(nfilt-1));
|
||||||
norm=norm+w[i];
|
norm=norm+w[i];
|
||||||
@ -657,7 +659,7 @@ unsigned long writec2file(char *c2filename, int trmin, double freq
|
|||||||
int i;
|
int i;
|
||||||
float *buffer;
|
float *buffer;
|
||||||
buffer=malloc(sizeof(float)*2*45000);
|
buffer=malloc(sizeof(float)*2*45000);
|
||||||
memset(buffer,0,sizeof(float)*2*45000);
|
for (i=0; i<2*45000; i++) buffer[i]=0.0;
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
@ -755,14 +757,16 @@ int main(int argc, char *argv[])
|
|||||||
memset(hashtab,0,sizeof(char)*32768*13);
|
memset(hashtab,0,sizeof(char)*32768*13);
|
||||||
int nh;
|
int nh;
|
||||||
symbols=malloc(sizeof(char)*nbits*2);
|
symbols=malloc(sizeof(char)*nbits*2);
|
||||||
decdata=malloc(sizeof(char)*11);
|
decdata = malloc(sizeof(char)*11);
|
||||||
channel_symbols=malloc(sizeof(char)*nbits*2);
|
memset(decdata,0,sizeof(char)*11);
|
||||||
|
channel_symbols = malloc(sizeof(char)*nbits*2);
|
||||||
|
memset(channel_symbols,0,sizeof(char)*nbits*2);
|
||||||
|
|
||||||
callsign=malloc(sizeof(char)*13);
|
callsign=malloc(sizeof(char)*13);
|
||||||
call_loc_pow=malloc(sizeof(char)*23);
|
call_loc_pow=malloc(sizeof(char)*23);
|
||||||
float allfreqs[100];
|
float allfreqs[100];
|
||||||
char allcalls[100][13];
|
char allcalls[100][13];
|
||||||
memset(allfreqs,0,sizeof(float)*100);
|
for (i=0; i<100; i++) allfreqs[i]=0.0;
|
||||||
memset(allcalls,0,sizeof(char)*100*13);
|
memset(allcalls,0,sizeof(char)*100*13);
|
||||||
|
|
||||||
int uniques=0, noprint=0, ndecodes_pass=0;
|
int uniques=0, noprint=0, ndecodes_pass=0;
|
||||||
@ -786,6 +790,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
idat=malloc(sizeof(float)*maxpts);
|
idat=malloc(sizeof(float)*maxpts);
|
||||||
qdat=malloc(sizeof(float)*maxpts);
|
qdat=malloc(sizeof(float)*maxpts);
|
||||||
|
for (i=0; i<maxpts; i++) {
|
||||||
|
idat[i]=0.0;
|
||||||
|
qdat[i]=0.0;
|
||||||
|
}
|
||||||
|
|
||||||
while ( (c = getopt(argc, argv, "a:BcC:de:f:HJmqstwvz:")) !=-1 ) {
|
while ( (c = getopt(argc, argv, "a:BcC:de:f:HJmqstwvz:")) !=-1 ) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@ -965,7 +973,6 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
ndecodes_pass=0; // still needed?
|
ndecodes_pass=0; // still needed?
|
||||||
|
|
||||||
memset(ps,0.0, sizeof(float)*512*nffts);
|
|
||||||
for (i=0; i<nffts; i++) {
|
for (i=0; i<nffts; i++) {
|
||||||
for(j=0; j<512; j++ ) {
|
for(j=0; j<512; j++ ) {
|
||||||
k=i*128+j;
|
k=i*128+j;
|
||||||
@ -982,7 +989,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compute average spectrum
|
// Compute average spectrum
|
||||||
memset(psavg,0.0, sizeof(float)*512);
|
for (i=0; i<512; i++) psavg[i]=0.0;
|
||||||
for (i=0; i<nffts; i++) {
|
for (i=0; i<nffts; i++) {
|
||||||
for (j=0; j<512; j++) {
|
for (j=0; j<512; j++) {
|
||||||
psavg[j]=psavg[j]+ps[j][i];
|
psavg[j]=psavg[j]+ps[j][i];
|
||||||
@ -1439,6 +1446,14 @@ int main(int argc, char *argv[])
|
|||||||
fclose(fhash);
|
fclose(fhash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(hashtab);
|
||||||
|
free(symbols);
|
||||||
|
free(decdata);
|
||||||
|
free(channel_symbols);
|
||||||
|
free(callsign);
|
||||||
|
free(call_loc_pow);
|
||||||
|
free(idat);
|
||||||
|
free(qdat);
|
||||||
if( stackdecoder ) {
|
if( stackdecoder ) {
|
||||||
free(stack);
|
free(stack);
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ long unsigned int pack_grid4_power(char *grid4, int power) {
|
|||||||
long unsigned int pack_call(char *callsign) {
|
long unsigned int pack_call(char *callsign) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
long unsigned int n;
|
long unsigned int n;
|
||||||
char call6[6];
|
char call6[7];
|
||||||
memset(call6,32,sizeof(char)*6);
|
memset(call6,32,sizeof(char)*7);
|
||||||
// callsign is 6 characters in length. Exactly.
|
// callsign is 6 characters in length. Exactly.
|
||||||
size_t call_len = strlen(callsign);
|
size_t call_len = strlen(callsign);
|
||||||
if( call_len > 6 ) {
|
if( call_len > 6 ) {
|
||||||
@ -83,8 +83,8 @@ long unsigned int pack_call(char *callsign) {
|
|||||||
void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd ) {
|
void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd ) {
|
||||||
size_t i;
|
size_t i;
|
||||||
char *call6;
|
char *call6;
|
||||||
call6=malloc(sizeof(char)*6);
|
call6=malloc(sizeof(char)*7);
|
||||||
memset(call6,32,sizeof(char)*6);
|
memset(call6,32,sizeof(char)*7);
|
||||||
size_t i1=strcspn(callsign,"/");
|
size_t i1=strcspn(callsign,"/");
|
||||||
|
|
||||||
if( callsign[i1+2] == 0 ) {
|
if( callsign[i1+2] == 0 ) {
|
||||||
@ -142,6 +142,7 @@ void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd ) {
|
|||||||
*nadd=1;
|
*nadd=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(call6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void interleave(unsigned char *sym)
|
void interleave(unsigned char *sym)
|
||||||
@ -165,7 +166,8 @@ void interleave(unsigned char *sym)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* symbols) {
|
int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* symbols) {
|
||||||
int m=0, n=0, ntype=0;
|
int m=0, ntype=0;
|
||||||
|
long unsigned int n=0;
|
||||||
int i, j, ihash;
|
int i, j, ihash;
|
||||||
unsigned char pr3[162]=
|
unsigned char pr3[162]=
|
||||||
{1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,
|
{1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,
|
||||||
@ -227,14 +229,14 @@ int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* sym
|
|||||||
ihash=nhash(callsign,strlen(callsign),(uint32_t)146);
|
ihash=nhash(callsign,strlen(callsign),(uint32_t)146);
|
||||||
m=128*ihash + ntype + 64;
|
m=128*ihash + ntype + 64;
|
||||||
|
|
||||||
char grid6[6];
|
char grid6[7];
|
||||||
memset(grid6,32,sizeof(char)*6);
|
memset(grid6,0,sizeof(char)*7);
|
||||||
j=strlen(grid);
|
j=strlen(grid);
|
||||||
for(i=0; i<j-1; i++) {
|
for(i=0; i<j-1; i++) {
|
||||||
grid6[i]=grid[i+1];
|
grid6[i]=grid[i+1];
|
||||||
}
|
}
|
||||||
grid6[5]=grid[0];
|
grid6[5]=grid[0];
|
||||||
n=pack_call(grid6);
|
n = pack_call(grid6);
|
||||||
} else if ( i2 < mlen ) { // just looks for a right slash
|
} else if ( i2 < mlen ) { // just looks for a right slash
|
||||||
// Type 2: PJ4/K1ABC 37
|
// Type 2: PJ4/K1ABC 37
|
||||||
callsign=strtok(message," ");
|
callsign=strtok(message," ");
|
||||||
@ -297,7 +299,7 @@ int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* sym
|
|||||||
|
|
||||||
unsigned int nbytes=11; // The message with tail is packed into almost 11 bytes.
|
unsigned int nbytes=11; // The message with tail is packed into almost 11 bytes.
|
||||||
unsigned char channelbits[nbytes*8*2]; /* 162 rounded up */
|
unsigned char channelbits[nbytes*8*2]; /* 162 rounded up */
|
||||||
memset(channelbits,0,sizeof channelbits);
|
memset(channelbits,0,sizeof(char)*nbytes*8*2);
|
||||||
|
|
||||||
encode(channelbits,data,nbytes);
|
encode(channelbits,data,nbytes);
|
||||||
|
|
||||||
@ -306,6 +308,7 @@ int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* sym
|
|||||||
for (i=0; i<162; i++) {
|
for (i=0; i<162; i++) {
|
||||||
symbols[i]=2*channelbits[i]+pr3[i];
|
symbols[i]=2*channelbits[i]+pr3[i];
|
||||||
}
|
}
|
||||||
|
free(check_call_loc_pow);
|
||||||
|
free(check_callsign);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user