Skip to content

Commit 0861a86

Browse files
committed
manually merge some memory-related bugfixes from hyperbolic2346/motion
1 parent 925f82c commit 0861a86

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

netcam_rtsp.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,21 @@ static int netcam_read_rtsp_image(netcam_context_ptr netcam)
297297

298298
if(packet.stream_index != netcam->rtsp->video_stream_index) {
299299
// not our packet, skip
300+
av_free_packet(&packet);
301+
av_init_packet(&packet);
302+
packet.data = NULL;
303+
packet.size = 0;
300304
continue;
301305
}
302306

303307
size_decoded = decode_packet(&packet, buffer, frame, cc);
308+
if (size_decoded == 0)
309+
{
310+
av_free_packet(&packet);
311+
av_init_packet(&packet);
312+
packet.data = NULL;
313+
packet.size = 0;
314+
}
304315
}
305316

306317
if (size_decoded == 0) {
@@ -411,7 +422,7 @@ int netcam_setup_rtsp(netcam_context_ptr netcam, struct url_t *url)
411422
if ((cptr = strchr(ptr, ':')) == NULL) {
412423
netcam->rtsp->user = mystrdup(ptr);
413424
} else {
414-
netcam->rtsp->user = mymalloc((cptr - ptr));
425+
netcam->rtsp->user = mymalloc((cptr - ptr) + 2); // +2 for string terminator
415426
memcpy(netcam->rtsp->user, ptr,(cptr - ptr));
416427
netcam->rtsp->pass = mystrdup(cptr + 1);
417428
}

0 commit comments

Comments
 (0)