[FFmpeg-soc] [soc]: r5258 - in concat/libavformat: avplaylist.c avplaylist.h

gkovacs subversion at mplayerhq.hu
Tue Aug 25 08:30:43 CEST 2009


Author: gkovacs
Date: Tue Aug 25 08:30:43 2009
New Revision: 5258

Log:
check for realloc failures in av_playlist_add_path

Modified:
   concat/libavformat/avplaylist.c
   concat/libavformat/avplaylist.h

Modified: concat/libavformat/avplaylist.c
==============================================================================
--- concat/libavformat/avplaylist.c	Tue Aug 25 07:41:55 2009	(r5257)
+++ concat/libavformat/avplaylist.c	Tue Aug 25 08:30:43 2009	(r5258)
@@ -198,17 +198,34 @@ AVPlaylistContext *av_playlist_from_file
     return ctx;
 }
 
-void av_playlist_add_path(AVPlaylistContext *ctx, const char *itempath)
+int av_playlist_add_path(AVPlaylistContext *ctx, const char *itempath)
 {
     ctx->flist = av_realloc(ctx->flist, sizeof(*(ctx->flist)) * (++ctx->pelist_size+1));
     ctx->flist[ctx->pelist_size] = NULL;
     ctx->flist[ctx->pelist_size-1] = itempath;
-    ctx->durations = av_realloc(ctx->durations,
-                                sizeof(*(ctx->durations)) * (ctx->pelist_size+1));
+    int64_t *durations_tmp = av_realloc(ctx->durations,
+                                        sizeof(*(ctx->durations)) * (ctx->pelist_size+1));
+    if (!durations_tmp) {
+        av_log(NULL, AV_LOG_ERROR, "av_realloc error in av_playlist_add_path\n");
+        av_free(ctx->durations);
+        ctx->durations = NULL;
+        return AVERROR_NOMEM;
+    }
+    else
+        ctx->durations = durations_tmp;
     ctx->durations[ctx->pelist_size] = 0;
-    ctx->nb_streams_list = av_realloc(ctx->nb_streams_list,
-                                      sizeof(*(ctx->nb_streams_list)) * (ctx->pelist_size+1));
+    int *nb_streams_list_tmp = av_realloc(ctx->nb_streams_list,
+                                          sizeof(*(ctx->nb_streams_list)) * (ctx->pelist_size+1));
+    if (!nb_streams_list_tmp) {
+        av_log(NULL, AV_LOG_ERROR, "av_realloc error in av_playlist_add_path\n");
+        av_free(ctx->nb_streams_list);
+        ctx->nb_streams_list = NULL;
+        return AVERROR_NOMEM;
+    }
+    else
+        ctx->nb_streams_list = nb_streams_list_tmp;
     ctx->nb_streams_list[ctx->pelist_size] = 0;
+    return 0;
 }
 
 void av_playlist_relative_paths(char **flist,

Modified: concat/libavformat/avplaylist.h
==============================================================================
--- concat/libavformat/avplaylist.h	Tue Aug 25 07:41:55 2009	(r5257)
+++ concat/libavformat/avplaylist.h	Tue Aug 25 08:30:43 2009	(r5258)
@@ -110,8 +110,9 @@ AVPlaylistContext *av_playlist_from_file
 /** @brief Creates and adds AVFormatContext for item located at specified path to a AVPlaylistContext.
  *  @param ctx Pre-allocated AVPlaylistContext to add elements to.
  *  @param itempath Absolute path to item for which to add a playlist element.
+ *  @return Returns 0 upon success, or negative upon failure.
  */
-void av_playlist_add_path(AVPlaylistContext *ctx, const char *itempath);
+int av_playlist_add_path(AVPlaylistContext *ctx, const char *itempath);
 
 /** @brief Calculates the index of the playlist item which would contain the timestamp specified in AV_TIME_BASE units.
  *  @param ctx AVPlaylistContext within which the list of playlist elements and durations are stored.


More information about the FFmpeg-soc mailing list