]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/doalloc.c
ncurses 6.2 - patch 20210424
[ncurses.git] / ncurses / tinfo / doalloc.c
index 0bda12cae8be07c4fce3661a583e5e557d1994b9..e3b1a2e96c1bf378f2c0f70c8110762187ecfbb5 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 2020,2021 Thomas E. Dickey                                     *
  * Copyright 1998-2002,2012 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * Copyright 1998-2002,2012 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
 
 #include <curses.priv.h>
 
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: doalloc.c,v 1.13 2020/08/30 00:27:15 tom Exp $")
+MODULE_ID("$Id: doalloc.c,v 1.14 2021/04/24 23:43:39 tom Exp $")
 
 void *
 _nc_doalloc(void *oldp, size_t amount)
 {
     void *newp;
 
 
 void *
 _nc_doalloc(void *oldp, size_t amount)
 {
     void *newp;
 
-    if (oldp != 0) {
-       if ((newp = realloc(oldp, amount)) == 0) {
+    if (oldp != NULL) {
+       if (amount == 0) {
+           free(oldp);
+           newp = NULL;
+       } else if ((newp = realloc(oldp, amount)) == 0) {
            free(oldp);
            errno = ENOMEM;     /* just in case 'free' reset */
        }
            free(oldp);
            errno = ENOMEM;     /* just in case 'free' reset */
        }