Browse code

core: parser rr - clean partially cloned fields in case of error

(cherry picked from commit e4f6c660bd75cdb9ff0855fcb511673cc8ec00c4)

Daniel-Constantin Mierla authored on 26/10/2020 12:36:36
Showing 1 changed files
... ...
@@ -296,7 +296,8 @@ static inline int do_duplicate_rr(rr_t** _new, rr_t* _r, int _shm)
296 296
 			} else {
297 297
 				PKG_MEM_ERROR;
298 298
 			}
299
-			return -2;
299
+			ret = -2;
300
+			goto error;
300 301
 		}
301 302
 		memcpy(res, it, sizeof(rr_t));
302 303
 
... ...
@@ -313,7 +314,8 @@ static inline int do_duplicate_rr(rr_t** _new, rr_t* _r, int _shm)
313 314
 			LM_ERR("Error while duplicating parameters\n");
314 315
 			if (_shm) shm_free(res);
315 316
 			else pkg_free(res);
316
-			return -3;
317
+			ret = -3;
318
+			goto error;
317 319
 		}
318 320
 
319 321
 		xlate_pointers(it, res);
... ...
@@ -327,6 +329,18 @@ static inline int do_duplicate_rr(rr_t** _new, rr_t* _r, int _shm)
327 329
 		it = it->next;
328 330
 	}
329 331
 	return 0;
332
+
333
+error:
334
+	if(*_new != NULL) {
335
+		if (_shm) {
336
+			shm_free_rr(_new);
337
+		} else {
338
+			free_rr(_new);
339
+		}
340
+		*_new = NULL;
341
+	}
342
+
343
+	return ret;
330 344
 }
331 345
 
332 346