mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-02-03 09:44:24 -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;
|
||||
|
||||
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");
|
||||
if (fp == NULL) {
|
||||
@ -547,13 +547,15 @@ void subtract_signal2(float *id, float *qd, long np,
|
||||
cq=malloc(sizeof(float)*nc2);
|
||||
cfi=malloc(sizeof(float)*nc2);
|
||||
cfq=malloc(sizeof(float)*nc2);
|
||||
|
||||
memset(refi,0,sizeof(float)*nc2);
|
||||
memset(refq,0,sizeof(float)*nc2);
|
||||
memset(ci,0,sizeof(float)*nc2);
|
||||
memset(cq,0,sizeof(float)*nc2);
|
||||
memset(cfi,0,sizeof(float)*nc2);
|
||||
memset(cfq,0,sizeof(float)*nc2);
|
||||
|
||||
for (i=0; i<nc2; i++) {
|
||||
refi[i]=0.0;
|
||||
refq[i]=0.0;
|
||||
ci[i]=0.0;
|
||||
cq[i]=0.0;
|
||||
cfi[i]=0.0;
|
||||
cfq[i]=0.0;
|
||||
}
|
||||
|
||||
twopidt=2.0*pi*dt;
|
||||
|
||||
@ -600,7 +602,7 @@ void subtract_signal2(float *id, float *qd, long np,
|
||||
|
||||
//lowpass filter and remove startup transient
|
||||
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++) {
|
||||
w[i]=sin(pi*(float)i/(float)(nfilt-1));
|
||||
norm=norm+w[i];
|
||||
@ -657,7 +659,7 @@ unsigned long writec2file(char *c2filename, int trmin, double freq
|
||||
int i;
|
||||
float *buffer;
|
||||
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;
|
||||
|
||||
@ -755,14 +757,16 @@ int main(int argc, char *argv[])
|
||||
memset(hashtab,0,sizeof(char)*32768*13);
|
||||
int nh;
|
||||
symbols=malloc(sizeof(char)*nbits*2);
|
||||
decdata=malloc(sizeof(char)*11);
|
||||
channel_symbols=malloc(sizeof(char)*nbits*2);
|
||||
decdata = malloc(sizeof(char)*11);
|
||||
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);
|
||||
call_loc_pow=malloc(sizeof(char)*23);
|
||||
float allfreqs[100];
|
||||
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);
|
||||
|
||||
int uniques=0, noprint=0, ndecodes_pass=0;
|
||||
@ -786,6 +790,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
idat=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 ) {
|
||||
switch (c) {
|
||||
@ -965,7 +973,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
ndecodes_pass=0; // still needed?
|
||||
|
||||
memset(ps,0.0, sizeof(float)*512*nffts);
|
||||
for (i=0; i<nffts; i++) {
|
||||
for(j=0; j<512; j++ ) {
|
||||
k=i*128+j;
|
||||
@ -982,7 +989,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// 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 (j=0; j<512; j++) {
|
||||
psavg[j]=psavg[j]+ps[j][i];
|
||||
@ -1438,7 +1445,15 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
fclose(fhash);
|
||||
}
|
||||
|
||||
|
||||
free(hashtab);
|
||||
free(symbols);
|
||||
free(decdata);
|
||||
free(channel_symbols);
|
||||
free(callsign);
|
||||
free(call_loc_pow);
|
||||
free(idat);
|
||||
free(qdat);
|
||||
if( stackdecoder ) {
|
||||
free(stack);
|
||||
}
|
||||
|
@ -43,8 +43,8 @@ long unsigned int pack_grid4_power(char *grid4, int power) {
|
||||
long unsigned int pack_call(char *callsign) {
|
||||
unsigned int i;
|
||||
long unsigned int n;
|
||||
char call6[6];
|
||||
memset(call6,32,sizeof(char)*6);
|
||||
char call6[7];
|
||||
memset(call6,32,sizeof(char)*7);
|
||||
// callsign is 6 characters in length. Exactly.
|
||||
size_t call_len = strlen(callsign);
|
||||
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 ) {
|
||||
size_t i;
|
||||
char *call6;
|
||||
call6=malloc(sizeof(char)*6);
|
||||
memset(call6,32,sizeof(char)*6);
|
||||
call6=malloc(sizeof(char)*7);
|
||||
memset(call6,32,sizeof(char)*7);
|
||||
size_t i1=strcspn(callsign,"/");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
free(call6);
|
||||
}
|
||||
|
||||
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 m=0, n=0, ntype=0;
|
||||
int m=0, ntype=0;
|
||||
long unsigned int n=0;
|
||||
int i, j, ihash;
|
||||
unsigned char pr3[162]=
|
||||
{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);
|
||||
m=128*ihash + ntype + 64;
|
||||
|
||||
char grid6[6];
|
||||
memset(grid6,32,sizeof(char)*6);
|
||||
char grid6[7];
|
||||
memset(grid6,0,sizeof(char)*7);
|
||||
j=strlen(grid);
|
||||
for(i=0; i<j-1; i++) {
|
||||
grid6[i]=grid[i+1];
|
||||
}
|
||||
grid6[5]=grid[0];
|
||||
n=pack_call(grid6);
|
||||
n = pack_call(grid6);
|
||||
} else if ( i2 < mlen ) { // just looks for a right slash
|
||||
// Type 2: PJ4/K1ABC 37
|
||||
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 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);
|
||||
|
||||
@ -306,6 +308,7 @@ int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* sym
|
||||
for (i=0; i<162; i++) {
|
||||
symbols[i]=2*channelbits[i]+pr3[i];
|
||||
}
|
||||
|
||||
free(check_call_loc_pow);
|
||||
free(check_callsign);
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user