mirror of
				https://github.com/gnss-sdr/gnss-sdr
				synced 2025-10-31 07:13:03 +00:00 
			
		
		
		
	Fix memory leaks (Fixes: #342)
This commit is contained in:
		| @@ -172,12 +172,11 @@ void galileo_e1_code_gen_float_sampled(gsl::span<float> _dest, const std::array< | ||||
|     galileo_e1_code_gen_int(primary_code_E1_chips, _Signal, _prn);  // generate Galileo E1 code, 1 sample per chip | ||||
|  | ||||
|     const uint32_t _codeLength = _samplesPerChip * GALILEO_E1_B_CODE_LENGTH_CHIPS; | ||||
|     std::unique_ptr<float> _signal_E1{new float[_codeLength]}; | ||||
|     gsl::span<float> _signal_E1_span(_signal_E1, _codeLength); | ||||
|     std::vector<float> _signal_E1(_codeLength); | ||||
|  | ||||
|     if (_cboc == true) | ||||
|         { | ||||
|             galileo_e1_gen_float(_signal_E1_span, primary_code_E1_chips, _Signal);  // generate cboc 12 samples per chip | ||||
|             galileo_e1_gen_float(_signal_E1, primary_code_E1_chips, _Signal);  // generate cboc 12 samples per chip | ||||
|         } | ||||
|     else | ||||
|         { | ||||
| @@ -186,15 +185,15 @@ void galileo_e1_code_gen_float_sampled(gsl::span<float> _dest, const std::array< | ||||
|  | ||||
|             for (uint32_t ii = 0; ii < _codeLength; ++ii) | ||||
|                 { | ||||
|                     _signal_E1_span[ii] = static_cast<float>(_signal_E1_int[ii]); | ||||
|                     _signal_E1[ii] = static_cast<float>(_signal_E1_int[ii]); | ||||
|                 } | ||||
|         } | ||||
|  | ||||
|     if (_fs != _samplesPerChip * _codeFreqBasis) | ||||
|         { | ||||
|             std::unique_ptr<float> _resampled_signal{new float[_samplesPerCode]}; | ||||
|             std::vector<float> _resampled_signal(_samplesPerCode); | ||||
|  | ||||
|             resampler(gsl::span<float>(_signal_E1, _codeLength), gsl::span<float>(_resampled_signal, _samplesPerCode), _samplesPerChip * _codeFreqBasis, _fs);  // resamples code to fs | ||||
|             resampler(_signal_E1, _resampled_signal, _samplesPerChip * _codeFreqBasis, _fs);  // resamples code to fs | ||||
|  | ||||
|             _signal_E1 = std::move(_resampled_signal); | ||||
|         } | ||||
| @@ -203,16 +202,15 @@ void galileo_e1_code_gen_float_sampled(gsl::span<float> _dest, const std::array< | ||||
|         { | ||||
|             size_signal_E1 = _samplesPerCode; | ||||
|         } | ||||
|     gsl::span<float> _signal_E1_span_aux(_signal_E1, size_signal_E1); | ||||
|  | ||||
|     if (_galileo_signal.rfind("1C") != std::string::npos && _galileo_signal.length() >= 2 && _secondary_flag) | ||||
|         { | ||||
|             std::unique_ptr<float> _signal_E1C_secondary{new float[static_cast<int32_t>(GALILEO_E1_C_SECONDARY_CODE_LENGTH) * _samplesPerCode]}; | ||||
|             gsl::span<float> _signal_E1C_secondary_span(_signal_E1C_secondary, static_cast<int32_t>(GALILEO_E1_C_SECONDARY_CODE_LENGTH) * _samplesPerCode); | ||||
|             std::vector<float> _signal_E1C_secondary(static_cast<int32_t>(GALILEO_E1_C_SECONDARY_CODE_LENGTH) * _samplesPerCode); | ||||
|             for (uint32_t i = 0; i < static_cast<uint32_t>(GALILEO_E1_C_SECONDARY_CODE_LENGTH); i++) | ||||
|                 { | ||||
|                     for (unsigned k = 0; k < _samplesPerCode; k++) | ||||
|                     for (uint32_t k = 0; k < _samplesPerCode; k++) | ||||
|                         { | ||||
|                             _signal_E1C_secondary_span[i * _samplesPerCode + k] = _signal_E1_span_aux[k] * (GALILEO_E1_C_SECONDARY_CODE[i] == '0' ? 1.0F : -1.0F); | ||||
|                             _signal_E1C_secondary[i * _samplesPerCode + k] = _signal_E1[k] * (GALILEO_E1_C_SECONDARY_CODE[i] == '0' ? 1.0F : -1.0F); | ||||
|                         } | ||||
|                 } | ||||
|  | ||||
| @@ -220,14 +218,15 @@ void galileo_e1_code_gen_float_sampled(gsl::span<float> _dest, const std::array< | ||||
|  | ||||
|             _signal_E1 = std::move(_signal_E1C_secondary); | ||||
|         } | ||||
|  | ||||
|     if (_galileo_signal.rfind("1C") != std::string::npos && _galileo_signal.length() >= 2 && _secondary_flag) | ||||
|         { | ||||
|             size_signal_E1 = static_cast<int32_t>(GALILEO_E1_C_SECONDARY_CODE_LENGTH) * _samplesPerCode; | ||||
|         } | ||||
|     gsl::span<float> _signal_E1_span_aux2(_signal_E1, size_signal_E1); | ||||
|  | ||||
|     for (uint32_t i = 0; i < _samplesPerCode; i++) | ||||
|         { | ||||
|             _dest[(i + delay) % _samplesPerCode] = _signal_E1_span_aux2[i]; | ||||
|             _dest[(i + delay) % _samplesPerCode] = _signal_E1[i]; | ||||
|         } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -108,9 +108,8 @@ void galileo_e5_a_code_gen_complex_sampled(gsl::span<std::complex<float>> _dest, | ||||
|     const uint32_t _codeLength = GALILEO_E5A_CODE_LENGTH_CHIPS; | ||||
|     const int32_t _codeFreqBasis = GALILEO_E5A_CODE_CHIP_RATE_CPS; | ||||
|  | ||||
|     std::unique_ptr<std::complex<float>> _code{new std::complex<float>[_codeLength]}; | ||||
|     gsl::span<std::complex<float>> _code_span(_code, _codeLength); | ||||
|     galileo_e5_a_code_gen_complex_primary(_code_span, _prn, _Signal); | ||||
|     std::vector<std::complex<float>> _code(_codeLength); | ||||
|     galileo_e5_a_code_gen_complex_primary(_code, _prn, _Signal); | ||||
|  | ||||
|     _samplesPerCode = static_cast<uint32_t>(static_cast<double>(_fs) / (static_cast<double>(_codeFreqBasis) / static_cast<double>(_codeLength))); | ||||
|  | ||||
| @@ -118,8 +117,8 @@ void galileo_e5_a_code_gen_complex_sampled(gsl::span<std::complex<float>> _dest, | ||||
|  | ||||
|     if (_fs != _codeFreqBasis) | ||||
|         { | ||||
|             std::unique_ptr<std::complex<float>> _resampled_signal{new std::complex<float>[_samplesPerCode]}; | ||||
|             resampler(_code_span, gsl::span<std::complex<float>>(_resampled_signal, _samplesPerCode), _codeFreqBasis, _fs);  // resamples code to fs | ||||
|             std::vector<std::complex<float>> _resampled_signal(_samplesPerCode); | ||||
|             resampler(_code, _resampled_signal, _codeFreqBasis, _fs);  // resamples code to fs | ||||
|             _code = std::move(_resampled_signal); | ||||
|         } | ||||
|     uint32_t size_code = _codeLength; | ||||
| @@ -127,9 +126,8 @@ void galileo_e5_a_code_gen_complex_sampled(gsl::span<std::complex<float>> _dest, | ||||
|         { | ||||
|             size_code = _samplesPerCode; | ||||
|         } | ||||
|     gsl::span<std::complex<float>> _code_span_aux(_code, size_code); | ||||
|     for (uint32_t i = 0; i < _samplesPerCode; i++) | ||||
|         { | ||||
|             _dest[(i + delay) % _samplesPerCode] = _code_span_aux[i]; | ||||
|             _dest[(i + delay) % _samplesPerCode] = _code[i]; | ||||
|         } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Carles Fernandez
					Carles Fernandez